Thread: Figured it out

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    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.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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);

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    the drawing method isn't really my lag issue, its data management, the 3d array is a destroyer, translating with it = death to processor

Popular pages Recent additions subscribe to a feed

Similar Threads

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