QGLBuffer usage

1.7k Views Asked by At

I have some problems in understanding how to use QGLBuffer to render simple objects(like Rectangle for example). I'm trying to make selection rectangle for my app. here's the code example of what im doing :

class PlotGLWidget : public QGLWidget
 {
     Q_OBJECT
private:
QGLBuffer* m_ZoomRectBuffer;
public:
void initializeGL();
void paintGL();
void drawZoomRect();
};
void PlotGLWidget::initializeGL()
{
setMouseTracking (true);
glClearColor(1,1,1,0);
m_ZoomRectBuffer=new QGLBuffer(QGLBuffer::VertexBuffer);
m_ZoomRectBuffer->create();
m_ZoomRectBuffer->bind();
m_ZoomRectBuffer->setUsagePattern(QGLBuffer::DynamicDraw);
m_ZoomRectBuffer->allocate(8*sizeof(double));
m_ZoomRectBuffer->release();
}
void PlotGLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, this->width(), this->height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,100, 0,100, -1.0l, 0.0l);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
drawZoomRect();
}
void PlotGLWidget::drawZoomRect()
{
GLdouble vertices[] = {10, 10, 0, 
                      10,  20, 0, 
                      20,  20, 0, 
                      20, 10, 0}; 

     GLubyte indices[] = {0,1,2,3};
if(m_ZoomRectBuffer->bind()){
m_ZoomRectBuffer->write(0,vertices,sizeof(double)*12);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer( 3, GL_DOUBLE, 0, 0);
glDrawElements( GL_POLYGON, 4, GL_UNSIGNED_BYTE,indices);
glDisableClientState(GL_VERTEX_ARRAY);
m_ZoomRectBuffer->release();     
}

in spite of being just example im sure there are some mistakes in my code and my understanding of the technology. Code compiles without mistakes and runs, but nothing is drawing.

0

There are 0 best solutions below