Multimedia
  Home arrow Multimedia arrow Page 3 - Game Programming with SDL: Getting Started with OpenGL
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
MULTIMEDIA

Game Programming with SDL: Getting Started with OpenGL
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 25
    2007-07-10


    Table of Contents:
  • Game Programming with SDL: Getting Started with OpenGL
  • OpenGL: Basic Steps
  • SDL-Based Framework: Creating and Testing
  • Adding OpenGL

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Game Programming with SDL: Getting Started with OpenGL - SDL-Based Framework: Creating and Testing
    ( Page 3 of 4 )

    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
     

       

    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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek