Multimedia
  Home arrow Multimedia arrow Page 2 - 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 - OpenGL: Basic Steps
    ( Page 2 of 4 )

    Now that I've discussed the theory behind OpenGL, let's see how to put it to use. To draw any shape onto the screen, there are three main steps. They are:

    1. Clearing the screen
    2. Resetting the view
    3. Drawing the scene

    Of these the third step consists of multiple sub-steps. I'll cover the details next. 

    Clearing the Screen

    To set the stage for drawing, clearing the screen is a must. This can be done by using the glClear() command. This command clears the screen by setting the values of the bit plane area of the view port. glClear() takes a single argument that is the bitwise OR of several values indicating which buffer is to be cleared. The values of the parameter can be:

    • GL_COLOR_BUFFER_BIT, which indicates the buffers currently enabled for color writing have to be cleared.
    • GL_DEPTH_BUFFER_BIT, which is used to clear the depth buffer.
    • GL_ACCUM_BUFFER_BIT, which is used if the accumulation buffer has to be cleared. 
    • GL_STENCIL_BUFFER_BIT, which is passed as parameter when the stencil buffer has to be cleared.

    Next, the color to be used as the erasing color is specified. This can be done using glClearColor(). This command clears the color buffers specified. That means when the specified color buffers are cleared the screen is recreated accordingly. So to clear the depth buffer and set the clearing color to blue the statements would be:

    glClear(GL_DEPTH_BUFFER_BIT);
    glClearColor(0.0f,0.0f,1.0f,0.0f);

     Resetting the View

    The background and the required buffers have been cleared. But the actual model of the image is based on the view. The view can be considered the matrix representation of the image. In order to draw this matrix, it has to be configured as an identity. This is done using glLoadIdentity(). The statement would be:

    glLoadIdentity();

    Drawing the Scene

    To draw the scene we tell OpenGL to do two things: start and stop the drawing, and issue the drawing commands.

    Commands to start and stop the drawing are issued through the calls to glBegin() and glEnd(). The glBegin() command takes one parameter, namely the type of shape to be drawn. To draw using three points use GL_TRIANGLES. Use  GL_QUADS for points and GL_POLYGON for multiple points. The glEnd() command tells OpenGL to stop the drawing. For example, to draw a triangle the statements would be:

    glBegin(GL_TRIANGLES);
    :
    :
    glEnd();

    The drawing commands come between these commands.

    Within the drawing commands, vertex data is specified. These commands are of the type glVertex*f() where * corresponds to the number of parameters, either two or three. Each call creates a point and then connects it with the point created with the earlier call. So to create a triangle with the coordinates (0.0, 1.0, 0.0), (-1.0,-1.0, 0.0) and (1.0,-1.0, 0.0) the commands would be:

    glBegin(GL_TRIANGLES);
       glVertex3f( 0.0f, 1.0f, 0.0f);
       glVertex3f(-1.0f,-1.0f, 0.0f);
       glVertex3f( 1.0f,-1.0f, 0.0f);

    glEnd();

    That's all we need to cover about drawing objects with OpenGL. In the next section, these commands will be used to put the SDL-based framework to the test.



     
     
    >>> 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