Multimedia
  Home arrow Multimedia arrow Page 2 - Game Programming with SDL: Getting Sta...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
MULTIMEDIA

Game Programming with SDL: Getting Started with OpenGL
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 24
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Anyone looking for a way to modernize legacy data or easily migrate to a more cost-effective database without sacrificing functionality will benefit from this seminar. View the Intro to Advantage Database Server now!

    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


       · I had a quick look over the code and here are some things which need to be...
       · Thanks for your comment. Can you first tell me which OS and compiler are you using?...
       · This article looks more into the details of OpenGL. The framework developed has been...
       · I use windows linux and mac, the C language does not have built in boolean type( you...
     

       

    MULTIMEDIA ARTICLES

    - 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-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway