OpenGL with SDL

Started by
6 comments, last by Webbster 20 years, 4 months ago
Can I use OpenGL in conjunction with SDL to get the best of both worlds, as well as make the final product cross platform? My idea is to create my environments and graphics such as particle systems and models using OpenGL and then using SDL to create my app''s window and allow for Music, Sound and Input. Is this possible or am I missing something. Thanks Ad
Advertisement
Yes. Parts of SDL are specifically designed to make cross-platform OpenGL initialization very easy. Read the SDL docs.
That''s probably the most common use for SDL. You can find lots of examples at the bottom of the NeHE tutorials where most of them have an SDL example.

The official zorx website
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
On the tutorials section of the SDL website there''s a link to download the sources for the NeHe tutorials in SDL
-----Mr. Chainsaw came and took my legs a long, long time ago
The problem with SDL and OpenGL is that on Windows, SDL uses the old-school context set-up functions, so you can''t request modern features like pbuffers. Well, last I looked, anyway; I haven''t seen anything about updating it to use WGL_ARB_pixel_format so I think it''s still a limitation.
enum Bool { True, False, FileNotFound };
When it comes to using OpenGL in an SDL window, are their any alterations to the OGL code or is it a point of when I''ve initialized an SDL window, it just becomes a matter of creating the rest with OpenGL as normal. I haven''t really had time to study the SDL Docs much so any further help would be appreciated.

Thanks, Ad.

PS Are there any known performance hit''s concerning the use of SDL for sound and input along side OpenGL for Graphics?
Find time to read the docs

Basically all it requires is setting of a few flags. The above posters have pointed out a potential problem with relying on SDL, but for reasonably simple applications you shouldn''t have a problem.

As soon as OpenGL is initialized, it is no different to using it with your own init code, so there is no performance hit to using other libs along side than would result from doing it yourself.
This should setup SDL for you
void InitSDL(void){	if(SDL_Init(SDL_INIT_VIDEO) < 0)	{		ofstream fout("error.log");		fout << "Unable to Init SDL video!!\n";		fout.close();		exit(0);	}	if(SDL_SetVideoMode(1024, 768, 32, SDL_FULLSCREEN | SDL_OPENGL) == NULL)	{		ofstream fout("error.log");		fout << "Unable to Init SDL videomode!!\n";		fout.close();		SDL_Quit();		exit(0);	}}//end of void InitSDL(void)//**************************void InitOpenGL(int width, int height){	glViewport(0, 0, width, height);	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);						// This Will Clear The Background Color To Black	glClearDepth(1.0f);										// Enables Clearing Of The Depth Buffer	glDepthFunc(GL_LEQUAL);									// The Type Of Depth Test To Do	glEnable(GL_DEPTH_TEST);								// Enables Depth Testing	glEnable(GL_TEXTURE_2D);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);		// Linear Filtering	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);		// Linear Filtering	glGenTextures(3, texture);	glBindTexture(GL_TEXTURE_2D, texture[0]);	load_texture("bitmap.png");	glBindTexture(GL_TEXTURE_2D, texture[1]);	load_texture("bitmap1.png");	glBindTexture(GL_TEXTURE_2D, texture[2]);	load_texture("bitmap2.png");	glShadeModel(GL_SMOOTH);								// Enables Smooth Color Shading	glMatrixMode(GL_PROJECTION);	glLoadIdentity();										// Reset The Projection Matrix	gluPerspective(45.0f, (GLfloat) width/(GLfloat) height, 0.1f, 100.0f);		// Calculate The Aspect Ratio Of The Window	glMatrixMode(GL_MODELVIEW);}//end of void InitOpenGL(int height, int width)

Its bee awhile since I have used SDL so tread carefully.

This topic is closed to new replies.

Advertisement