Thread: Drawing a flag with glut library, what i'm doing wrong????

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    15

    Unhappy Drawing a flag with glut library, what i'm doing wrong????

    Hi people. My name is Samuel. I'm trying to draw a simple flag, using the glut library on C. For your information, I have my experience working with C# and C++ but I have never tried C before. I let you guys know that so you know that you can talk me with concepts and I will understand. I just copy/paste a code at the web which suppose to draw a simple white and red lines in order to can create a flag with a star on it after that. The code that I have is as follow:

    Code:
    #include "windows.h"
    #include "stdafx.h"
    #include "glut.h"
    #include <cmath>
    
    void DrawStripes ()
    
    {
    int iStripes = 5;
    
    float fDeltaY = 1.0 / iStripes;
    
    
    
    float fStartX = 0.0;
    
    float fEndX = 1.0;
    
    
    
    for (int iStripeIndex = 0; iStripeIndex < 5; ++iStripeIndex) {
    
    
    	if (iStripeIndex % 2 == 0) {
    
          glColor3f(204.0/255.0, 0.0, 0.0); // to make the red color
    
    } else {
    
             glColor3f(1.0, 1.0, 1.0); // to make the white color
    
    }
    
    
    
    float fStartY = iStripeIndex*fDeltaY;
    
    float fEndY = (iStripeIndex + 1)*fDeltaY;
    
    
    
    glBegin(GL_QUADS);
    
    glVertex2f(fStartX, fStartY);
    
    glVertex2f(fEndX, fStartY);
    
    glVertex2f(fEndX, fEndY);
    
    glVertex2f(fStartX, fEndY);
    
    glEnd();
    
    }
    
    }
    
    void Initialize() {
    
                glClearColor(0.0, 0.0, 0.0, 0.0);
    
                glMatrixMode(GL_PROJECTION);
    
                glLoadIdentity();
    
                glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    
    }
    void Draw() {
    
              
    	
    DrawStripes();
    
    			
              
    
    }
    
    int main(int iArgc, char** cppArgv) {
    
                glutInit(&iArgc, cppArgv);
    
                glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    
                glutInitWindowSize(900, 500);
    
                glutInitWindowPosition(200, 200);
    
                glutCreateWindow("Bandera de Puerto Rico");
    
                Initialize();
    
                glutDisplayFunc(Draw);
    
                glutMainLoop();
    
                return 0;
    
    }
    I run the code and the output is just a white screen. A professor says that he made this code as an example and it should be showing the output that you can see in this link:

    http://i1227.photobucket.com/albums/...t1/Coutput.png

    I don't have experience in C but knowing C++ I still cant find the error. I'm sorry if this is a dumb question but if someone can help me to get the right output I will really appreciate it.

    Samuel

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    I don't know how GLUT_SINGLE buffering works. But if you change that to GLUT_DOUBLE and change your Draw routine to the following it should work:
    Code:
    void Draw() {
        glClear(GL_COLOR_BUFFER_BIT);
        DrawStripes();
        glutSwapBuffers();
    }
    Actually, it just occurred to me that simply putting glFlush() (if that's the right command) after DrawStripes might make it work with GLUT_SINGLE. Drawing commands are buffered in OpenGL if I remember correctly.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC Header File Library Flag Listing?
    By LinuxSmith in forum Linux Programming
    Replies: 9
    Last Post: 08-15-2010, 07:42 PM
  2. Easiest 2D drawing library for bloodshed compiler?
    By thunderchief in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2005, 02:25 PM
  3. glut text rendering in wrong color
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 10-31-2005, 10:02 PM
  4. Drawing a circle using glut...
    By bennyho03 in forum C Programming
    Replies: 6
    Last Post: 10-18-2004, 10:06 AM
  5. Looking for a gcc flag
    By JLWinsett in forum Linux Programming
    Replies: 4
    Last Post: 12-26-2002, 11:39 AM