Opengl-Buffer question?

Started by
15 comments, last by V-man 15 years, 5 months ago
I have to visualize a "chess-board" but with more than 160.000 sqaures each colored according to some measurment-values. I'm usging wxWidgets with a wxGLCanvas-object. Now i set up a glOrtho (only 2D is needed) and paint the squares. I'm using multiple windows so more "measurement-objects" could be viewn. Now i had the problem with scroll, size, overlapping,..., everything that calls a PaintEvent. There are to many float-values to render it every-time. So i tried following trick:
[source==cpp]
OnPaint(..)
{
 if(first)
 {
   glDrawBuffer(GL_FRONT);
   Render(); 

   glDrawBuffer(GL_BACK);
   Render();
  first = false;
 }
 SwapBuffers();
}


But this code makes errors on some systems, picture is getting blurred and black, a total mass. Now i'm seraching for some kind of buffer-object or anything like this!? instead of rendering it everytime (it's not animated!). Any suggestions?
Advertisement
Why do you call
glDrawBuffer(GL_FRONT);
Render();

Also, get rid of if(first)
so that it renders.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
As i said: "There are too many float-values to render it every-time."

If I render it every-PaintEvent it's bucking hard.
Rendering 160000 texels every frame is not a significant problem if you're doing it efficiently. What method do you use to draw the chessboard?
My favorite method is to render to a texture as a temporary storage. Then render a big quad all over your screen.
Example to create a RTT

http://www.opengl.org/wiki/index.php/GL_EXT_framebuffer_object
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I tried it with a FBO-Object but have this problem:
http://www.gamedev.net/community/forums/topic.asp?topic_id=515600

My draw-Method for every cell looks like this:
void GLCanvas::drawCell(int *x_pos, int *y_pos, int bin_value) {         right_x  = x_offset * (*x_pos + 1);   left_x   = x_offset * (*x_pos);   top_y    = y_offset * (*y_pos + 1);   bottom_y = y_offset * (*y_pos);        glColor3f(0.5f, 0.5f, 0.2f);   glBegin(GL_LINE_LOOP);    glVertex2i(right_x, top_y);    glVertex2i(left_x,  top_y);    glVertex2i(left_x,  bottom_y );    glVertex2i(right_x, bottom_y);   glEnd();        // switch colour depending on the bin-value        wxColour *colour = mdi_parent_ptr->getColour(bin_value);    convertColourTo3f(colour);         //if((bin_value != REF_DIE) && (bin_value != REF_DIE2))    glRecti(right_x, top_y, left_x, bottom_y);        // draw a point in the middle of all none good-dies   if(bin_value != 0x01)   {     // set color black     glColor3f(0.0f, 0.0f, 0.0f);     // set point size according the scale     glPointSize(point_size);     glBegin(GL_POINTS);       glVertex2i(left_x + x_offset / 2, bottom_y + y_offset / 2);     glEnd();   }  }


I still reduced it to integer-values and also made tried it with a display-list.

Calling it @ a for-loop:
for(int index = 0; index < num_of_dies; index++){     x = wafer_ptr->getDie(index)->getXcoord();     y = wafer_ptr->getDie(index)->getYcoord();     b = wafer_ptr->getDie(index)->getBinValue();     drawCell(&x, &y, b);      }


Probably this could be made faster in a int-array?(think so)
Yeah, that's going to be really, really slow. High-performance OpenGL requires that you NOT draw 640 thousand vertices with glVertex. Put all your square values in a texture and render that texture using a single quad.
General question on Window-buffers.

Why is it necessary to render the whole scene again if e.g. scroll-event occurs.
Why do the window itself doesn't store the picture temporary and just call a buffer if it is overlapped or scrolled.

I can't imagine that this is made with repaintings?
Quote:Original post by frog04
General question on Window-buffers.

Why is it necessary to render the whole scene again if e.g. scroll-event occurs.
Why do the window itself doesn't store the picture temporary and just call a buffer if it is overlapped or scrolled.

I can't imagine that this is made with repaintings?

I don't know wx, but i imagine they do window stuff simply by drawing on top of the GL canvas ? Caching makes sense only in limited cases where the scene is static (not your usual GL app), meaning it's your job to do so. Simply render the scene to texture (or use glCopyTexImage* to copy the rendered scene from framebuffer to texture), then on repaint draw fullscreen quad with the texture. This will be fast everywhere.
Quote:Original post by frog04
General question on Window-buffers.

Why is it necessary to render the whole scene again if e.g. scroll-event occurs.
Why do the window itself doesn't store the picture temporary and just call a buffer if it is overlapped or scrolled.

I can't imagine that this is made with repaintings?


Because normally, the backbuffer is not preserved when you call SwapBuffers. The driver can just switch pointers so that the back buffer becomes the front buffer and the front becomes back.
The driver can do all sorts of crazy things.

You can try setting the PFD_SWAP_COPY but personally, I would recommend the RTT method I already mentioned.

Swapbuffers issue
http://www.opengl.org/wiki/index.php/Common_Mistakes#Swap_Buffers
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement