Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 11th, 2007, 7:44 PM   #1
csrocker101
Programmer
 
Join Date: Dec 2006
Posts: 49
Rep Power: 0 csrocker101 is on a distinguished road
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
csrocker101 is offline   Reply With Quote
Old Apr 11th, 2007, 11:20 PM   #2
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 4 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
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
Wizard1988 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:58 PM.

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