Results 1 to 7 of 7

Thread: Why I can't get through the simplest code??

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2002
    Location
    Th
    Posts
    5

    Why I can't get through the simplest code??

    Hello, I'm a very beginner in OpenGL. The problem is that I try to write a very simple code using C++Builder, actually it's a first code in the red book drawing white rectangle on black background. There is no any error while compile...but when running, nothing came out. It's just a blank form and the background color still be a button face color. So...help me please... :'(

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2001
    Location
    Omaha, NE US
    Posts
    119

    Re: Why I can't get through the simplest code??

    Are you forgetting to put glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); before all your drawing code?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2002
    Location
    Th
    Posts
    5

    Re: Why I can't get through the simplest code??

    again, Here is my code:-

    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0,1.0,1.0);
    glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
    glBegin(GL_POLYGON);
    glVertex2f(-0.5,-0.5);
    glVertex2f(-0.5,0.5);
    glVertex2f(0.5,0.5);
    glVertex2f(0.5,-0.5);
    glEnd();
    glFlush();

    I put it on a FormPaint event. nothing happens...why?
    Thanks - job

  4. #4
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    133

    Re: Why I can't get through the simplest code??

    If you drawing with a 3d matrix, you'll
    have to step back a little to see your scene.

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 60, winwidth / winheight, 1, 10 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    /* step back from origin for our view */

    glTranslatef( 0, 0, -5 );

    /* draw 3d stuff at origin by starting with a new
    matrix */

    glPushMatrix();

    /* drawing code here */

    glPopMatrix();

    SwapBuffers();
    --
    Jim Mathies http://www.mathies.com/

    \"The best way to predict the future is to invent it."

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2002
    Location
    Th
    Posts
    5

    Re: Why I can't get through the simplest code??

    Thanks, but it's still the same.

  6. #6
    Member Contributor
    Join Date
    Jun 2001
    Posts
    55

    Re: Why I can't get through the simplest code??

    did you initialize a valid render context and made it current?

  7. #7
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    477

    Re: Why I can't get through the simplest code??

    Put this code in your DrawGL function, this work.


    // Clear the color buffer and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Reset the axes
    glLoadIdentity();

    // The camera location
    /*
    0,0,5 ==> Eye location
    0,0,0 ==> The place where the eye's looking
    0,1,0 ==> The directionnal vector
    */
    gluLookAt(0,0,5,0,0,0,0,1,0);

    glBegin(GL_QUADS);
    glVertex2i(-1,1);
    glVertex2i(-1,-1);
    glVertex2i(1,-1);
    glVertex2i(1,1);
    glEnd();

Similar Threads

  1. Simplest GLUT alternative?
    By Lindley in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 10-28-2007, 08:16 PM
  2. Problems with the simplest code with opengl
    By tiregarfio in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-25-2006, 04:25 AM
  3. the simplest problem ever
    By completelyuniquename in forum OpenGL: User Software
    Replies: 1
    Last Post: 10-04-2004, 02:46 PM
  4. simplest shadows?
    By c_olin in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-25-2003, 12:12 AM
  5. what is simplest way to handle a click?
    By dogar in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-17-2002, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean