I've read some tutorials on how to set up OpenGl with SDL but they don't work.
Right now all i want to do is draw a simple triangle on the screen but i cant figure out how to initalize OpenGL without getting
"undefined reference to ' INSERT OPENGL FUNCTION HERE' "
Here is what i've got for the code:
#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
#include "SDL_opengl.h"
#include <GL/gl.h>
#include <GL/glu.h>
SDL_Surface* drawContext;
SDL_Event event;
Uint32 flags;
int main ( int argc, char** argv ){
//void draw_screen( void );
void InitOpenGL(int width , int height);
void ListenForEvents(SDL_Event & event);
int error;
error = SDL_Init(SDL_INIT_EVERYTHING);
atexit(SDL_Quit);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
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);
flags = SDL_OPENGL | SDL_FULLSCREEN;
drawContext = SDL_SetVideoMode(640, 480, 0, flags);
InitOpenGL (640,480);
while(true){
SDL_PollEvent(&event);
ListenForEvents(event);
}
return 0;
}
void ListenForEvents(SDL_Event & event){
if(event.type == SDL_QUIT){
exit(1);
}else{
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
exit(1);
break;
}
}
SDL_GL_SwapBuffers( );
SDL_Delay(20);
}
void InitOpenGL(int width , int height){
float ratio = (float) width / (float) height;
/* Our shading model--Gouraud (smooth). */
glShadeModel( GL_SMOOTH );
/* Culling. */
glCullFace( GL_BACK );
glFrontFace( GL_CCW );
glEnable( GL_CULL_FACE );
/* Set the clear color. */
glClearColor( 0, 0, 0, 0 );
/* Setup our viewport. */
glViewport( 0, 0, width, height );
/*
* Change to the projection matrix and set
* our viewing volume.
*/
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
/*
* EXERCISE:
* Replace this with a call to glFrustum.
*/
gluPerspective( 60.0, ratio, 1.0, 1024.0 );
}
So my question is : Can anyone Tell me where i went wrong and how i can fix this?