Home arrow Multimedia arrow Page 3 - Game Programming with SDL: Getting Started with OpenGL

SDL-Based Framework: Creating and Testing - Multimedia

SDL helps to provide a framework on which to build games. OpenGL is the graphic library most commonly used with this framework. This article shows you how these two technologies work together.

TABLE OF CONTENTS:
  1. Game Programming with SDL: Getting Started with OpenGL
  2. OpenGL: Basic Steps
  3. SDL-Based Framework: Creating and Testing
  4. Adding OpenGL
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 25
July 10, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Up to now I have discussed SDL's various APIs. Now it's time to put them together so that working with OpenGL and SDL becomes easy. So here we go. The framework is based upon NeHe's excellent framework for SDL.net -- the .Net port of SDL.

First the includes:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/gl.h>  // The OpenGL
#include <GL/glu.h> // and OpenGL utility
#include <SDL.h>    // and SDL headers

Here are the global variables which save the state of the surface and the program:

bool isProgramLooping;//This one is being used to know if the program
                     
//needs to be continued or exited
SDL_Surface *Screen;

Now the common functionalities: initialization, termination and full-screen toggling.

bool Initialize(void)// Any Application & User Initialization Code would be here
{
  
AppStatus.Visible= true; // When program begins, the
                            // application window is
                            // visible
  
AppStatus.MouseFocus= true;// and have both mouse
  
AppStatus.KeyboardFocus = true;// and input focus

   // start of user initialization. These are just examples
  
angle = 0.0f;// Set the starting angle to zero
  
cnt1= 0.0f;// Set the cos(for the x axis) counter to zero
  
cnt2= 0.0f;// Set the sin(for the y axis) counter to zero

   {
    
printf("Cannot load graphic: %sn", SDL_GetError() );
    
return false;
  
}

   return true;
          // return true if initialization is successful
}

void Deinitialize(void) // Any User Deinitialization such as releasing file handles etc has to be performed here
{
  
return;
}

void TerminateApplication(void)// terminate the application
{
  
static SDL_Event Q;// This function sends aSDL_QUIT event
  
Q.type = SDL_QUIT;// to the sdl event queue
  
if(SDL_PushEvent(&Q) == -1) // Sending the event

   {
    
printf("SDL_QUIT event can't be pushed: %sn", SDL_GetError() ); exit(1);
       // And Exit
  
}

}

void ToggleFullscreen(void)// Toggle Fullscreen/Windowed
                           //(Works On
Linux/BeOS Only)
{
  
SDL_Surface *S; // a surface to point the screen
  
S = SDL_GetVideoSurface(); // gets the video surface
  
if(!S || (SDL_WM_ToggleFullScreen(S)!=1))
      // If SDL_GetVideoSurface Fails, Or if cant toggle to fullscreen
   
{
    
printf("Unable to toggle fullscreen: %sn", SDL_GetError() );
     // only reporting the error, not exiting
  
}

}



 
 
>>> More Multimedia Articles          >>> More By A.P.Rajshekhar
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

MULTIMEDIA ARTICLES

- Basic Lighting in OpenGL and SDL Game Progra...
- Working with Colors in OpenGL for Game Progr...
- Animation in OpenGL for Game Programming usi...
- Game Programming with SDL: Getting Started w...
- Using OpenGL with SDL for Game Programming
- Learning Sound for Game Programming using SDL
- Game Programming using SDL: Raw Graphics and...
- Game Programming using SDL: Getting Started
- Network Radio With Icecast
- Learning To SMILe

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: