C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-06-2005, 12:26 AM   #1
Absent Minded Programmer
 
Join Date: May 2005
Posts: 933
Figured it out

There it is, vertex array, my simple primitive, if I were to use this, in conjunction with a high speed grid drawing function, we'd have a beautifully smooth program


Code:
float array[9] = {1.0, -1.0, 0.0,								// 3 coordinates per vertex
                     0.0, 1.0, 0.0,								// Using GLFloat as the data type
                     -1.0, -1.0, 0.0};							// Assume that there is no padding between coordinate values
	glVertexPointer(3, GL_FLOAT, 0, array);						// Pointer to the first element in the array

	glEnableClientState(GL_VERTEX_ARRAY);
		glDrawArrays(GL_TRIANGLES, 0, 3);
	glDisableClientState(GL_VERTEX_ARRAY);
Fast Grid Drawer thing

Code:
void DrawSquare(int left, int top, int right, int bottom)
{
	glBegin(GL_LINES);
	glColor4f(1, 1, 1, 1);
	glVertex2d(left, top);
	glVertex2d(right, top);

	glVertex2d(right, top);
	glVertex2d(right, bottom);

	glVertex2d(right, bottom);
	glVertex2d(left, bottom);

	glVertex2d(left, bottom);
	glVertex2d(left, top);
	glEnd();
}

void DrawGrid(int left, int top, int right, int bottom, int w, int h)
{
	for(int i=left; i<right; i+= w)
	{
		for(int o=top; o<bottom; o+= h)
		{
			DrawSquare(i,o,i+w,o+h );
		}
	}
}
Then we use the vertex arrays to draw a primitive when I click a certain area of the grid and colorfy it...

remove all those stupid unecessary loops.... yeah... smooth program, thanks all who have helped

I can do this
Seats Seat[392]

because element=row*width+column, I can get to a certain section very easily....

instead of Seats Seat[3][14][28]....

and then translatef with a much better algorithm

definately not

Code:
				s[0][k][j].x=k*19.0f;	
				s[0][k][j].y=j*19.0f;					
				glTranslatef(s[0][k][j].x,s[0][k][j].y,0.0f);
instead of doing that, i'll make an algorithm to detect mouse detection, and create a quad on demand with a mouse click to make the color changes and the seat will be sold...

that is the program killer right there, its making everything slow, if edited out, program runs beautifully....

something is making me think, why do i need to fudge with s[][][].x at all? why do i have the x/y in the structure? I don't need to store that information, i don't need that info at all, because i'm drawing the grid with lines, and then im creating the quads at a mouse click with vertex arrays, which are uber fast and dynamic, therefore I can change the stuff in them, and draw different things, thats uber!

Last edited by Shamino; 11-06-2005 at 12:39 AM.
Shamino is offline   Reply With Quote
Old 11-06-2005, 12:43 AM   #2
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,596
For something static like that you might get better performance using pre-compiled display lists.

Code:
GLuint list = glGenLists((GLuint) 1);

glNewList(list, GL_COMPILE);
/* all your draw commands go here */
glEndList();

/* call it with */
glTranslate( /* object coords */ );
glCallList(list);
Perspective is offline   Reply With Quote
Old 11-06-2005, 12:55 AM   #3
Absent Minded Programmer
 
Join Date: May 2005
Posts: 933
the drawing method isn't really my lag issue, its data management, the 3d array is a destroyer, translating with it = death to processor
Shamino is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
figured it out but have one question romeoz C++ Programming 5 07-08-2003 07:49 PM
I figured out my other problem, but... hpy_gilmore8 C++ Programming 18 04-22-2003 10:59 PM
Now that I have figured out sound, Vanished Game Programming 2 12-09-2002 04:01 PM
I have figured out the differences between 95 and XP... DavidP A Brief History of Cprogramming.com 6 04-03-2002 03:47 PM
I just figured this method out. knave C++ Programming 2 09-13-2001 11:39 PM


All times are GMT -6. The time now is 12:13 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22