Using OpenGL with SDL

Started by
1 comment, last by thecoast47 12 years, 10 months ago
So im trying to use OpenGL with SDL..
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?
Advertisement
Make sure you're linking to the OpenGL library or libraries. (The details will depend on the development environment.)

Make sure you're linking to the OpenGL library or libraries. (The details will depend on the development environment.)


Yeah...the problem was letting code blocks handle linking SDL.
I had to change the way i set up SDL libraries and add links in the build options.
Problem solved I'm happily, and successfully, rendering 3D cubes with no problems.

This topic is closed to new replies.

Advertisement