Jump to content
  • Advertisement
Sign in to follow this  
srodgers

OpenGL 3D OpenGL with SDL

This topic is 3733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include "SDL/SDL.h" #include "SDL/SDL_opengl.h" //---------------- #define TRUE 1 #define FALSE 0 #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 #define SCREEN_BPP 24 //---------------- static void init(); static void renderCube(); //---------------- int main( int argc, char *argv[] ) { SDL_Event evnt; int quit = FALSE; float ang = 0.0f; init(); //-- Main Loop --// while( !quit ) { //-- Process Events --// while( SDL_PollEvent( &evnt ) ) { if( evnt.type == SDL_QUIT ) { quit = TRUE; } else if ( evnt.type == SDL_KEYDOWN ) { if ( evnt.key.keysym.sym == SDLK_ESCAPE ) { quit = TRUE; } } } //-- Render Screen --// glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); glTranslatef(0.0f,0.0f,-6.0f); glRotatef( ang, 0.5f, 1.0f, 0.2f ); renderCube(); ang += 0.5f; SDL_GL_SwapBuffers(); } //-- Clean Up --// SDL_Quit(); return 0; } //---------------- static void init() { //create window SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ); //projection glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); glMatrixMode( GL_PROJECTION ); gluPerspective( 45.0f, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 1.0f, 1000.0f ); //other glMatrixMode( GL_MODELVIEW ); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); glClearDepth( 1.0f ); glShadeModel( GL_SMOOTH ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); //assert( glGetError() == GL_NO_ERROR ); SDL_WM_SetCaption( "Testing", NULL ); } //---------------- static void renderCube() { glBegin(GL_QUADS); glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top) glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top) glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top) glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top) glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom) glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom) glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom) glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom) glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front) glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front) glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front) glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front) glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back) glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back) glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back) glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back) glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left) glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left) glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left) glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left) glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right) glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right) glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right) glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right) glEnd(); }

Share this post


Link to post
Share on other sites
Advertisement
This has to be one of the worst posts of all time! ;) I can't help without knowing the question.

But I will take a stab. It looks like some fine code, run with it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!