Results 1 to 5 of 5

Thread: Display Problems

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    United Kingdom
    Posts
    7

    Display Problems

    Hi,
    I am trying to write a program to draw the Serpinski Gasket. The code compiles fine but then when I run the program all I get is an empty, see-through window (not a pretty fractal).
    Why is this?
    Here is my code:

    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <stdlib.h>
    #include <gl/gl.h>
    #include <gl/glut.h>

    class GLintPoint{
    public:

    GLint x, y;
    };

    void myInit(void)
    {
    glClearColor(1.0,1.0,1.0,0.0);
    glColor3f(0.0f, 0.0f, 0.0f);
    glPointSize(4.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 640.0, 0.0, 480.0);
    }

    void drawDot(GLint x , GLint y)
    {
    glBegin(GL_POINTS);
    glVertex2i(x, y);
    glEnd();
    }

    void Sierpinski(void)
    {
    GLintPoint T[3]= {(10,10), (300,30), (200, 300)};

    int index = random(3);
    GLintPoint point = T[index];
    drawDot(point.x, point.y);
    for(int i = 0; i < 1000; i++)
    {
    index = random(3);
    point.x = (point.x + T[index].x) / 2;
    point.y = (point.y = T[index].y) / 2;
    drawDot(point.x, point.y);
    }
    glFlush();

    }

    void main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(100, 150);
    glutCreateWindow("The Sierpinski Gasket");
    glutDisplayFunc(Sierpinski);
    myInit();
    glutMainLoop();

    }

    Its my first proper OpenGL program so its probably something really simple.

    Phil

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    184

    Re: Display Problems

    you need to load the MODELVIEW matrix when displaying geometry. put this after your call to gluOrtho2D:

    glMatrixMode(GL_MODELVIEW);

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

    Re: Display Problems

    glMatrixMode(GL_MODELVIEW) is, in this case, not needed. Once the projection matrix is set, he don't touch the matrix stack at all.

    As for the problem, i suspect it's black lines on a black window. You set the clear color to white, but you don't call glClear(GL_COLOR_BUFFER_BIT) to clear the buffer.

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    United Kingdom
    Posts
    7

    Re: Display Problems

    Thanks for that I have a white b/g now.
    Unfortunately the program doesnt create the picture its supposed to. I think its because the random number part isn't doing what I want it to.

    What does the command random(3) actually do?

    What I want to do is randomly generate numbers 1,2 or 3 so I randomly select one of the points in the array T.

    I would guess from the output I am getting that I am always selecting T[1] and never any of the others.

    Phil

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    United Kingdom
    Posts
    7

    Re: Display Problems

    Have just checked my code and found mistake in the maths

    I also think I remember reading that the first position in an array is 0 not 1 so I'll rephrase what I wrote above.

    Having corrected the maths (It should have read "point.y = (point.y + T[index].y) / 2;") I get an output more like what I expected. However, I still don't think the code ever selects T[2] since all the dots are at the bottom of the screen.

    Since I don't know much about C++ an explanation of what random(3) does might help here.

    Cheers and sorry bout the previous post,

    Phil

Similar Threads

  1. Display List Problems
    By ToddAtWSU in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-28-2006, 07:12 PM
  2. Display problems
    By Vlasko in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-16-2003, 01:35 PM
  3. Screen display problems
    By in forum OpenGL: Linux
    Replies: 8
    Last Post: 01-10-2003, 06:12 AM
  4. Display List Problems...
    By choi1012 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-29-2002, 05:36 AM
  5. Color display problems
    By jgrashow in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-14-2000, 09:09 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