Ok here is my problem. I run VC++6, and when i compile this code it comes up without flaws, but when i compile/execute this code, it comes up with about 20 different link errors. All of the errors consist of a gl command. aka. glvertex3f, glnormal, etc. When i compile the code without the windows header, i only have 3 errors, but they are centered in the gl header file, so I am sure that this header needs to be here for gl.h to work. I link SDL up by setting my code generation to multithreading dll, and add the lib files to my directory, and project so i know thats working. also i have tried to add the gl32.lib, glu32.lib, and glu.lib files to my project, but that doesnt work either. Any suggestions as to what i am doing wrong???
PS.
This code really dosnt do much, i am just trying to prove that SDL and OpenGL work togeather.
Thanks
#include <windows.h>
#include <SDL.h>
#include <gl\gl.h>
#include <gl\glu.h>
void SetupRC();
void ChangeSize(int, int);
void RenderScene();
void InputHandler();
void HandleKeyboardEvent(SDL_Event *event);
void HandleMouseEvent(SDL_Event *event);
int main()
{
const SDL_VideoInfo* info = NULL;
int w = 0;
int h = 0;
int bpp = 0;
int flags = 0;
SDL_Init( SDL_INIT_VIDEO );
info = SDL_GetVideoInfo( );
w = 640;
h = 480;
bpp = info->vfmt->BitsPerPixel;
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
flags = SDL_OPENGL | SDL_FULLSCREEN;
SDL_SetVideoMode( w, h, bpp, flags );
ChangeSize( w, h );
SetupRC();
while( 1 )
{
InputHandler( );
RenderScene( );
}
return 0;
}
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glBegin(GL_TRIANGLE_STRIP);
glNormal3f(-0.9f, -0.5f, -0.2f);
glVertex3f(0.0f, 0.0f, -10.0f);
glVertex3f(2.0f, 0.0f, -10.0f);
glVertex3f(1.0f, 2.0f, -10.0f);
glNormal3f(-0.9f, -0.3f, 0.1f);
glVertex3f(3.0f, 4.0f, -20.0f);
glEnd();
glPopMatrix();
SDL_GL_SwapBuffers( );
}
void SetupRC()
{
float ambient0[] = {0.3f, 0.3f, 0.3f, 1.0f};
float diffuse0[] = {0.7f, 0.7f, 0.7f, 1.0f};
float specular0[] = {0.8f, 0.8f, 0.8f, 1.0f};
float specref0[] = {0.8f, 0.8f, 0.8f, 1.0f};
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient0);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse0);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular0);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT, GL_SPECULAR, specref0);
glMateriali(GL_FRONT, GL_SHININESS, 100);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glColor3f(1.0f, 0.0f, 0.0f);
}
void ChangeSize(int w, int h)
{
float lightpos0[] = {-50.0f, 50.0f, 100.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_POSITION, lightpos0);
float fAspect;
if(h==0)
h=1;
glViewport(0,0,w,h);
fAspect = (float)w/(float)h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, fAspect, 1.0f, 400.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void InputHandler()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
case SDL_KEYUP:
HandleKeyboardEvent(&event);
break;
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
HandleMouseEvent(&event);
break;
}
}
}
void HandleKeyboardEvent(SDL_Event *event)
{
SDL_KeyboardEvent *key=&event->key;
switch(key->keysym.sym)
{
case SDLK_LEFT:
break;
case SDLK_RIGHT:
break;
default:
break;
}
switch(key->type)
{
case SDL_KEYUP:
break;
case SDL_KEYDOWN:
break;
default:
break;
}
}
void HandleMouseEvent(SDL_Event *event)
{
SDL_MouseMotionEvent *motion=&event->motion;
SDL_MouseButtonEvent *button=&event->button;
switch(event->type)
{
case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONDOWN:
break;
case SDL_MOUSEBUTTONUP:
break;
default:
break;
}
}