Halcom
26th October 2010, 10:17
Hallo,
i use Qt 4.7 and want to draw a textured quad, because glDrawPixels is to slow. The texture changed every time i want to redraw, because it cames from a framegrabber.
I Have read some tutorials, the problems is, that he only draw my first image, a gray 256x256 texture. The second one a 512x512 white not. The image buffers and sizes are changed correctly. So i miss something else.
It will be nice if someone could help me.
Here my paintGL method from my QGLWidget. A whole test project is attached.
thanks
void GUIGLView::glInit()
{
}
void GUIGLView::paintGL()
{
qglClearColor(QColor(Qt::black));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// only do something if image is availible
if(mImageData.imageBuffer == NULL)
return;
QString debugString = QString("paintGL called with buffer: 0x%1, size %2").arg((int)mImageData.imageBuffer,8,16,QChar('0')) .arg(mImageData.width);
qDebug(debugString.toAscii().data());
// set projection - disable z-axis
glMatrixMode(GL_PROJECTION);
//clear projection matrix
glLoadIdentity();
//Creating an orthoscopic view matrix going from -1 -> 1 in each
//dimension on the screen (x, y, z).
glOrtho(0, 640, 480, 0, -1, 1);
//Now editing the model-view matrix.
glMatrixMode(GL_MODELVIEW);
//Clearing the model-view matrix.
glLoadIdentity();
//Disabling the depth test (z will not be used to tell what object
//will be shown above another, only the order in which I draw them.)
glDisable(GL_DEPTH_TEST);
// generate a texture
glGenTextures(1, &mTextureID);
// enable texturing
glEnable(GL_TEXTURE_2D);
//specify texture to use
glBindTexture(GL_TEXTURE_2D, mTextureID);
// set texturing parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// copy image to texture
glTexImage2D(GL_TEXTURE_2D, 0, mImageData.samplesPerPixel, mImageData.width, mImageData.height, 0, GL_RGB, GL_UNSIGNED_BYTE, mImageData.imageBuffer);
// draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f( 0, 0,0); //lo
glTexCoord2f(0,1); glVertex3f(256, 0,0); //lu
glTexCoord2f(1,1); glVertex3f(256, 256,0); //ru
glTexCoord2f(1,0); glVertex3f( 0, 256,0); //ro
glEnd;
glDeleteTextures(1, &mTextureID);
mTextureID = 0;
}
i use Qt 4.7 and want to draw a textured quad, because glDrawPixels is to slow. The texture changed every time i want to redraw, because it cames from a framegrabber.
I Have read some tutorials, the problems is, that he only draw my first image, a gray 256x256 texture. The second one a 512x512 white not. The image buffers and sizes are changed correctly. So i miss something else.
It will be nice if someone could help me.
Here my paintGL method from my QGLWidget. A whole test project is attached.
thanks
void GUIGLView::glInit()
{
}
void GUIGLView::paintGL()
{
qglClearColor(QColor(Qt::black));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// only do something if image is availible
if(mImageData.imageBuffer == NULL)
return;
QString debugString = QString("paintGL called with buffer: 0x%1, size %2").arg((int)mImageData.imageBuffer,8,16,QChar('0')) .arg(mImageData.width);
qDebug(debugString.toAscii().data());
// set projection - disable z-axis
glMatrixMode(GL_PROJECTION);
//clear projection matrix
glLoadIdentity();
//Creating an orthoscopic view matrix going from -1 -> 1 in each
//dimension on the screen (x, y, z).
glOrtho(0, 640, 480, 0, -1, 1);
//Now editing the model-view matrix.
glMatrixMode(GL_MODELVIEW);
//Clearing the model-view matrix.
glLoadIdentity();
//Disabling the depth test (z will not be used to tell what object
//will be shown above another, only the order in which I draw them.)
glDisable(GL_DEPTH_TEST);
// generate a texture
glGenTextures(1, &mTextureID);
// enable texturing
glEnable(GL_TEXTURE_2D);
//specify texture to use
glBindTexture(GL_TEXTURE_2D, mTextureID);
// set texturing parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// copy image to texture
glTexImage2D(GL_TEXTURE_2D, 0, mImageData.samplesPerPixel, mImageData.width, mImageData.height, 0, GL_RGB, GL_UNSIGNED_BYTE, mImageData.imageBuffer);
// draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f( 0, 0,0); //lo
glTexCoord2f(0,1); glVertex3f(256, 0,0); //lu
glTexCoord2f(1,1); glVertex3f(256, 256,0); //ru
glTexCoord2f(1,0); glVertex3f( 0, 256,0); //ro
glEnd;
glDeleteTextures(1, &mTextureID);
mTextureID = 0;
}