Results 1 to 4 of 4

Thread: Empty window or invisible circle?

  1. #1
    Guest

    Empty window or invisible circle?

    Please help me?
    Having combined some poached circle code and a sample program, my supposedly red circle doesn't appear. Is "(GL_COLOR_BUFFER_BIT);" in the wrong place, or is it something more serious? I don't think the "double buffer" problem applies in this case.
    Thanks...


    /* 4th attempt to draw a red circle on a white background*/

    #include <GL/glut.h>
    #include <stdlib.h>
    #include <math.h>

    void myinit(void)
    {

    /* attributes */

    glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
    glColor3f(1.0, 0.0, 0.0); /* draw in red */

    /* set up viewing */
    /* 500 x 500 window with origin lower left */

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 500.0, 0.0, 500.0);
    glMatrixMode(GL_MODELVIEW);
    }

    void display( void )
    {
    GLint t;
    GLfloat CIRCLE_RES;
    GLfloat M_PI;

    glClear(GL_COLOR_BUFFER_BIT); /*clear the window */


    glBegin(GL_LINE_LOOP);
    for(t=0;t<CIRCLE_RES;t++)
    {
    GLfloat angle=((GLfloat)t/(GLfloat)CIRCLE_RES)*2.0*M_PI;
    glVertex2f(cos(angle), sin(angle));
    }
    glEnd();

    glFlush(); /* clear buffers */
    }

    void main(int argc, char** argv)
    {

    /* Standard GLUT initialization */

    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
    glutInitWindowSize(500,500); /* 500 x 500 pixel window */
    glutInitWindowPosition(0,0); /* place window top left on display */
    glutCreateWindow("Circle"); /* window title */
    glutDisplayFunc(display); /* display callback invoked when window opened */

    myinit(); /* set attributes */

    glutMainLoop(); /* enter event loop */
    }

  2. #2
    Member Newbie
    Join Date
    Oct 2002
    Location
    Rijeka, Croatia
    Posts
    36

    Re: Empty window or invisible circle?

    First, glLoadIdentity() after the Modelview Matrix has been established.

    Second, your circle has no radius.

    r*cos(phi) for Y, and r*sin(phi) for X.

    Third, it is much easier to draw in degrees, not radians:

    // translate to center of the circle
    // setup r and Z

    for (int i=0; i<360; i+=ANGLE_STEP) {
    float phi= i*PI/180;
    Y= r * cos(phi);
    X= r * sin(phi);
    glVertex3f(X, Y, Z);
    }

    Hope this helps.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Empty window or invisible circle?

    First, glLoadIdentity() after the Modelview Matrix has been established.
    Not needed. He's not touching the modelview matrix, and it's set to identity by default. It's good practice to explicitly set it though, but not needed.
    Second, your circle has no radius.
    His circle has radius 1.
    Third, it is much easier to draw in degrees, not radians:
    That's a personal taste, and don't forget that you have to convert it to radians anyways.

    I bet you have a circiel in the very bottom left corner of your window. Your window is 500x500 large, but your circle is only covering the very bottom left pixel, since it has radius 1 with origin at (0,0). Increase the radius and see what happens.

  4. #4
    Member Newbie
    Join Date
    Oct 2002
    Location
    Rijeka, Croatia
    Posts
    36

    Re: Empty window or invisible circle?

    Hello...

    Certain hardware implementations demand explicit reset of MODELVIEW matrix identity...

    His circle has a radius of 1, yes, but if you notice the viewport size (of 500x500), the circle is smaller than a pixel... perhaps I should have said that way...

    Finally, drawing in degrees is much simplier because of the control over the circle, and is much easier to debug. All he has to do is to set the appropriate circle step, and has 360 degrees of freedom, as per 4 df with radians, fractions not included.

Similar Threads

  1. Replies: 4
    Last Post: 05-31-2016, 05:21 PM
  2. Empty Window with OpenGL and DisplayLink
    By TheVyax in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-02-2012, 03:55 PM
  3. rendering in an invisible window
    By James W. Walker in forum OpenGL: Windows
    Replies: 4
    Last Post: 12-14-2007, 01:52 PM
  4. Why Does This Program Display Only An Empty Screen Window?
    By sjsearcher in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-08-2002, 12:20 PM
  5. Empty display window(issue urgent)
    By marysowdha in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-06-2001, 07:03 PM

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