trouble with wglGetProcAddress(

Greetings!

I am trying to compile and run a simple 3D texturing program. I have lines:
#include “glext.h”
PFNGLTEXIMAGE3DPROC glTexImage3D = NULL;
glTexImage3D = (PFNGLTEXIMAGE3DPROC)wglGetProcAddress(“glTexImage3DEXT”);

glTexImage3D(GL_TEXTURE_3D, 0, 3, 16, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE,
Texture);

I compile it OK, but when executing get an
“Unhandled Exception: 0xC000005 Access violation”. The debugger shows that glTexImage3D got assinged the following address: 0x000000000
It looks like wglGetProcAddress did not work. I have w2k.

What graphics card do you have? glTexImage3D is only available if OpenGL version is 1.2 or greater. Use glGetString with GL_VERSION to find your version. If less than 1.2 then that is the reason. Otherwise, your code looks correct.

You must not call wglGetProcAddress (or glGetString etc), without a valid GL context. In other words, open your GL window etc BEFORE getting the function pointer.

Originally posted by marcus256:
You must not call wglGetProcAddress (or glGetString etc), without a valid GL context. In other words, open your GL window etc BEFORE getting the function pointer.

All right then! How to open a GL win before getting the fucntion pointer. I have the following code with str returning 1.2.1 (it’s supposed to draw a small 3D tex’d cube):

#include <GL/glut.h>
#include “glext.h”
#include “extgl.h”
#include <math.h>
#ifndef M_PI

define M_PI 3.141592649

#endif /* !M_PI */

/*

  • Globals…
    */

int Width; /* Width of window /
int Height; /
Height of window /
GLubyte Texture[16][16][16][3]; /
Texture image /
PFNGLTEXIMAGE3DPROC glTexImage3D = NULL;
char str[10000];
/

  • Functions…
    */

void MakeTexture(void);
void Redraw(void);
void Resize(int width, int height);

/*

  • ‘main()’ - Open a window and display a textured sky.
    */

int /* O - Exit status /
main(int argc, /
I - Number of command-line arguments */
char argv[]) / I - Command-line arguments */
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH);
glutInitWindowSize(792, 573);
glutCreateWindow(“3D Textured Cut-Away Cube”);
glutReshapeFunc(Resize);
glutDisplayFunc(Redraw);

strcpy(str,glGetString(GL_VERSION));
MakeTexture();
glTexImage3D = (PFNGLTEXIMAGE3DPROC)wglGetProcAddress("glTexImage3DEXT");
glutMainLoop();
return (0);
}

/*

  • ‘MakeTexture()’ - Make the 3D texture image…
    */

void
MakeTexture(void)
{
int i, j, k; /* Looping vars /
GLubyte colors[8][3] =
{
{ 255, 255, 255 }, /
White /
{ 255, 0, 0 }, /
Red /
{ 255, 63, 0 }, /
Orange /
{ 255, 255, 0 }, /
Yellow /
{ 0, 255, 0 }, /
Green /
{ 0, 255, 255 }, /
Blue /
{ 0, 0, 255 }, /
Indigo /
{ 255, 0, 255 } /
Violet */
};

/* Set the color layers */
for (k = 0; k &lt; 8; k ++)
    for (i = 1; i &lt; 15; i ++)
        for (j = 1; j &lt; 15; j ++)
        {
        /* Top */
        Texture[16 - k][i][j][0] = colors[k][0];
        Texture[16 - k][i][j][1] = colors[k][1];
        Texture[16 - k][i][j][2] = colors[k][2];
        /* Bottom */
        Texture[k][i][j][0] = colors[k][0];
        Texture[k][i][j][1] = colors[k][1];
        Texture[k][i][j][2] = colors[k][2];
        /* Left */
        Texture[j][i][k][0] = colors[k][0];
        Texture[j][i][k][1] = colors[k][1];
        Texture[j][i][k][2] = colors[k][2];
        /* Right */
        Texture[j][i][16 - k][0] = colors[k][0];
        Texture[j][i][16 - k][1] = colors[k][1];
        Texture[j][i][16 - k][2] = colors[k][2];
        /* Front */
        Texture[i][k][j][0] = colors[k][0];
        Texture[i][k][j][1] = colors[k][1];
        Texture[i][k][j][2] = colors[k][2];
        /* Back */
        Texture[i][16 - k][j][0] = colors[k][0];
        Texture[i][16 - k][j][1] = colors[k][1];
        Texture[i][16 - k][j][2] = colors[k][2];
        }
}

/*

  • ‘Redraw()’ - Redraw the window…
    */

void
Redraw(void)
{
/* Define the 3D texture image. */
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

if(glTexImage3D!=NULL)
glTexImage3D(GL_TEXTURE_3D, 0, 3, 16, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE,
           Texture);
glEnable(GL_TEXTURE_3D);
glEnable(GL_DEPTH_TEST);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glTranslatef(0.0, 0.0, -50.0);
glRotatef(45.0, 0.0, 1.0, 0.0);

glColor3f(1.0, 1.0, 1.0);

/* Draw a 3D cube with a quadrant cut away... */
glBegin(GL_TRIANGLE_STRIP);

glTexCoord3f(0.0, 0.0, 0.0);
glVertex3f(-10.0, -10.0, 10.0);
glTexCoord3f(0.0, 1.0, 0.0);
glVertex3f(-10.0, 10.0, 10.0);

glTexCoord3f(0.5, 0.0, 0.0);
glVertex3f(0.0, -10.0, 10.0);
glTexCoord3f(0.5, 1.0, 0.0);
glVertex3f(0.0, 10.0, 10.0);

glTexCoord3f(0.5, 0.0, 0.5);
glVertex3f(0.0, -10.0, 0.0);
glTexCoord3f(0.5, 1.0, 0.5);
glVertex3f(0.0, 10.0, 0.0);

glTexCoord3f(1.0, 0.0, 0.5);
glVertex3f(10.0, -10.0, 0.0);
glTexCoord3f(1.0, 1.0, 0.5);
glVertex3f(10.0, 10.0, 0.0);

glTexCoord3f(1.0, 0.0, 1.0);
glVertex3f(10.0, -10.0, -10.0);
glTexCoord3f(1.0, 1.0, 1.0);
glVertex3f(10.0, 10.0, -10.0);

glEnd();

glPopMatrix();

glFinish();
}

/*

  • ‘Resize()’ - Resize the window…
    */

void
Resize(int width, /* I - Width of window /
int height) /
I - Height of window /
{
/
Save the new width and height */
Width = width;
Height = height;

/* Reset the viewport... */
glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, (float)width / (float)height, 0.1, 1000.0);

glMatrixMode(GL_MODELVIEW);
}

glutcreatewindow(blah blah)
is where your window is created. You have it in the right spot. if wglGetProcAddress(blah) returns 0, then your card/driver doesn’t support it (at least its that way for me).