Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Help with an openGL program (http://www.programmingforums.org/showthread.php?t=12979)

csrocker101 Apr 11th, 2007 8:44 PM

Help with an openGL program
 
Ok so basically I've got an openGL program and currently I am having two problems. My first problem I am having is trying to make an array of references of a method that will draw a quads. The draw method to draw the quad is my Building.h header file and in my main.cpp I have a drawing function which repeatidly gets called and this is where I called my drawquad method. I have made an instance of the Building class called Building b;

:

Building bvoid DrawScene(void)

{
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // draws Building
        b.drawBuilding();
                glEnd();
                glutSwapBuffers();
}
;


My drawing code works but I am trying to draw multiple buildings and want to make multiple instances of the building class. I have done this before in C# but am unsure of how to do it in C++. I tried doing:

:

Building b[6];

void DrawScene(void)
{
                for(int i = 0; i < 6; i++)
                {
                        b[i] = new Building;
                }
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // draws Building
        b.drawBuilding();
                glEnd();
                glutSwapBuffers();
}


something to that affect and then scale up the x factors but I am not sure how to accomplish this. Another problem I am having is I am making a random number generator which generates a random height for the y values in the quad.
:

srand((unsigned)time(0));
const double Random_Height = (rand()%400)+50;
glVertex2d(x + 0, y + Random_Height);
glVertex2d(x + 75, y + Random_Height);


but the problem is when I call my drawQuad method inside my draw function which repeatidly gets called, the drawQuad method continues to generate a random number and a random height and my quad grows and shrinks because the method is repeatidly called generating a new random number everytime. Any suggestions on how to fix these problems??


Quote:

A Thousand years from now, computer scientists will look at my code and laugh :rolleyes:

Wizard1988 Apr 12th, 2007 12:20 AM

Can you explain why you need multiple instances of the building class?. As for the random numbers being generated, you should calculate them on startup and just store them for use later on when they are needed.


All times are GMT -5. The time now is 2:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC