Advertisement

glXGetProcAddress vs glXGetProcAddressARB

Started by June 15, 2005 08:18 AM
1 comment, last by Cocalus 19 years, 4 months ago
In this thread, people were having problems with my GLSL test program. After doing some more research I found out a few things. On the FC1 machine at the university, I cannot compile any program using glXGetProcAddress(ARB). Using the following source:

#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glxext.h>

int main( int argc, char *argv[] )
{
	glXGetProcAddress((const unsigned char*)"whatever");
	glXGetProcAddressARB((const unsigned char*)"whatever");

	return 0;
}

and compiling with:

all: main.o
	g++ -g -o test.x main.o -L/usr/X11R6/lib -lGL -lGLU -lXxf86vm

main.o: main.cpp
	g++ -g -c main.cpp
I get 'glXGetProcAddressARB undeclared' during compilation. If I comment that line, I get 'undefined reference to glXGetProcAddress' during linking. I've also tried to manually declare glXGetProcAddressARB with:

extern void (*glXGetProcAddressARB(const GLubyte *procname))(void);
but then, it too gives 'undefined reference' during linking. So how on earth am I supposed to use extensions on this linux installation? This pc has an NVidia card, and it's drivers are installed and working. I'll update the post in a few hours with the exact results on my own linux install, but it isn't much better there. According to what I've been able to google, the seems due to different versions of header and library files. But I though I would have solved that by manually defining the *ARB variant. Apparently I haven't. I've also tried to compile GLEW, but it gave the same errors.
See here

Quote:
Actually what I did was use the ARB version and define GLX_GLXEXT_PROTOTYPES to force a static link. Seems to work fine.


so maybe that's what you should try. Find the one that works, and link it statically.

btw, you said in the previous thread that you can't use glsl functions without getting the pointer. Are you sure you have the latest glext.h? When I played around with glsl in linux, I don't remember having to get the function pointers. Maybe that's my faulty memory though.
Advertisement
Here's something I whipped up (the shaders came from www.lighthouse3d.com) that works on my system (which had the problem), this uses GLEW and SDL (next to no error checking but it should be fine for a working GLSL linux example).
#include <SDL.h>#include <GL/glew.h> //replaces SDL_opengl.h#include <iostream>using namespace std;const int Width = 800;const int Height = 600;SDL_Surface *screen;bool done = false;GLUquadricObj *quadratic;GLhandleARB vertexShader,fragmentShader,programObject;const GLcharARB *vextexProgram="varying vec3 normal, lightDir;""void main()""{""	lightDir = normalize(vec3(gl_LightSource[0].position));""	normal = normalize(gl_NormalMatrix * gl_Normal);""	gl_Position = ftransform();""}";const GLcharARB* fragmentProgram="varying vec3 normal, lightDir;""void main()""{""	float intensity;""	vec3 n;""	vec4 color;""	n = normalize(normal);""	intensity = max(dot(lightDir,n),0.0); ""	if (intensity > 0.98)""		color = vec4(0.8,0.8,0.8,1.0);""	else if (intensity > 0.5)""		color = vec4(0.4,0.4,0.8,1.0);	""	else if (intensity > 0.25)""		color = vec4(0.2,0.2,0.4,1.0);""	else""		color = vec4(0.1,0.1,0.1,1.0);""	gl_FragColor = color;""}";void  initWindow(){  SDL_Init(SDL_INIT_EVERYTHING);  SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);  SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,24);  screen = SDL_SetVideoMode(Width, Height, 32, SDL_OPENGL | SDL_HWSURFACE);  SDL_WM_SetCaption ("SDL+OpenGL+GLEW", NULL);}void initGL(){  glViewport(0, 0, Width,Height);  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  gluPerspective(45.0f,Width/Height,0.1f,1000.0f);  glMatrixMode(GL_MODELVIEW);  glClearColor(0.5f, 0.4f, 0.3f, 1.0);  glEnable(GL_DEPTH_TEST);  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	  glEnable(GL_LIGHTING);  float AmbientColor[]	= { 0.0f, 0.1f, 0.2f, 0.0f };         glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientColor);  float DiffuseColor[]	= { 1.0f, 1.0f, 1.0f, 1.0f };  glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseColor);  float SpecularColor[]	= { 0.0f, 0.0f, 0.0f, 0.0f };	      glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularColor);  float Position[]      = { 100.0f, 100.0f, 100.0f, 1.0f };  glLightfv(GL_LIGHT0, GL_POSITION, Position);  glEnable(GL_LIGHT0);  quadratic=gluNewQuadric();  gluQuadricNormals(quadratic, GLU_SMOOTH);}void drawGL(){  static float xrot=0.0;  static float yrot=0.0;  xrot += 0.02;  yrot += 0.02;  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );  glLoadIdentity( );  glTranslatef( 0.0f, 0.0f, -5.0f);  glRotatef( xrot, 1.0f, 0.0f, 0.0f);  glRotatef( yrot, 0.0f, 1.0f, 0.0f);  gluSphere(quadratic,1.3f,32,32);}void processInput(){  SDL_Event event;  while (SDL_PollEvent (&event)){    switch (event.type){     case SDL_KEYDOWN:      switch (event.key.keysym.sym){      case SDLK_ESCAPE:	done = true;	break;      default:	break;      }      break;    case SDL_QUIT:      done = true;      break;    default:      break;    }  }  }void setupshader(){  vertexShader=glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);  fragmentShader=glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);    glShaderSourceARB(vertexShader, 1, &vextexProgram,NULL);  glShaderSourceARB(fragmentShader, 1, &fragmentProgram,NULL);    glCompileShaderARB(vertexShader);  glCompileShaderARB(fragmentShader);  programObject = glCreateProgramObjectARB();  glAttachObjectARB(programObject,fragmentShader);  glAttachObjectARB(programObject,vertexShader);  glLinkProgramARB(programObject);  glUseProgramObjectARB(programObject);}int main(int argc, char *argv[]){  initWindow();  initGL();    GLenum err = glewInit();  if (err != GLEW_OK)    cout << reinterpret_cast<const char*>(glewGetErrorString(err)) << endl;  if ((!GLEW_ARB_vertex_shader) || (!GLEW_ARB_fragment_shader)){    cout << "Missing extensions" << endl;    exit(-1);  }  setupshader();  while (!done){    processInput();    drawGL();    SDL_GL_SwapBuffers();  }  SDL_Quit();}


It's compiled with
g++ -lGLEW `sdl-config --cflags --libs` filename

[edit]fixed a bug and added argc and argv so it'll compile in windows with dev-cpp[/edit]

[Edited by - Cocalus on June 16, 2005 5:48:14 AM]

This topic is closed to new replies.

Advertisement