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]