PDA

View Full Version : Im attempting to make OpenGL and SDL work hand in hand. Here is my problem.



dabeav
09-16-2001, 03:55 PM
When i compile my source code(Listed below) i get this error.

c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing ';' before type 'void'
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

which refers to the gl/gl header file. But i have not change this file so why would it be corrupt. Here is my source code. It is simply an attempt to get the SDL input syntax, and opengl syntax to work. Any suggestions on how to make it work??

#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;
}
}

shehz
09-16-2001, 04:16 PM
#include "windows.h" at the top of all the includes..it worked for me

dabeav
09-16-2001, 04:50 PM
well that works right up to the point when i try to compile/execute the program.

then i end up with A BUNCH!! of linking errors, most pertaining to gl function calls.

Any more suggestions

Aldacron
09-16-2001, 08:59 PM
Are you linking to gl32.lib and glu32.lib?