![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programmer
Join Date: Dec 2006
Posts: 49
Rep Power: 0
![]() |
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:
|
|
|
|
|
|
|
#2 |
|
Professional Programmer
|
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.
__________________
JG-Webdesign |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| program resulting in an executable. | sagedavis | C++ | 30 | Jan 31st, 2007 3:06 PM |
| Language display in program | Prm753 | C++ | 3 | May 30th, 2006 5:45 PM |
| Creating a program to test a program | sixstringartist | C | 8 | Jan 21st, 2006 1:15 PM |
| move program console window back | badbasser98 | C++ | 21 | Oct 18th, 2005 2:02 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |