Qt and OpenGL
Posted: Thu Aug 11, 2011 7:40 am
Okay so I've been learning Qt for some time now and I tried to implement some OpenGL which has gone well until now....
I've got rendering itself working fine, but texturing is proving to be less simple.
I load here I load the texture:
And draw it like this:
And if it's any use, here is the paintGL() function:
It gets rendered, but it's just a white square.
Unless something obvious is staring me in the face, am I missing something?
Thanks.
I've got rendering itself working fine, but texturing is proving to be less simple.
I load here I load the texture:
Code: Select all
void Eternal::Texture::Load(std::string file)
{
glEnable(GL_TEXTURE_2D);
QImage t;
QImage b;
// This file definitely exists
b.load( "content/test.png" );
t = QGLWidget::convertToGLFormat( b );
glGenTextures( 1, &g_Tex );
glBindTexture( GL_TEXTURE_2D, g_Tex );
glTexImage2D( GL_TEXTURE_2D, 1, 4, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glDisable(GL_TEXTURE_2D);
// "Pos" is a rectangle , the rest can be ignored ( not being used yet )
Pos.x = Pos.y = Crop.x = Crop.y = 0;
Pos.w = Crop.w = fWidth = t.width();
Pos.h = Crop.h = fHeight = t.height();
}
Code: Select all
void Eternal::Texture::Render()
{
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, g_Tex );
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(Pos.x,Pos.y);
glTexCoord2f(1,0); glVertex2f(Pos.x + Pos.w,Pos.y);
glTexCoord2f(1,1); glVertex2f(Pos.x + Pos.w,Pos.y + Pos.h);
glTexCoord2f(0,1); glVertex2f(Pos.x,Pos.y + Pos.h);
glEnd();
}
And if it's any use, here is the paintGL() function:
Code: Select all
void Eternal::GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
Img.Render();
}
Unless something obvious is staring me in the face, am I missing something?
Thanks.