Jump to content
  • Advertisement
Sign in to follow this  
ShabbaStoney

OpenGL RE : *SOLVED* glGenTextures & Qt

This topic is 2858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm new to OpenGL and I'm having a bit of bother with texturing. I can get it to work but not sure if it's supposed to. I am using Qt and it's QGLWidget.

At the moment I have this in initializeGL() :



// bind the texture
glGenTextures( 1, texture_ );
glBindTexture( GL_TEXTURE_2D, texture_[0] );

img = QGLWidget::convertToGLFormat( img );
terrainData_ = new QImage( img );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );





...where img and terrainData_ are a QImage.

And in my render part I have :



glTexImage2D( GL_TEXTURE_2D, 0, 4, terrainData_->width(), terrainData_->height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, terrainData_->bits() );

glBegin( GL_TRIANGLE_STRIP );

// .. render level here





Now the problem is if I comment out :



//glGenTextures( 1, texture_ );
//glBindTexture( GL_TEXTURE_2D, texture_[0] );





...then the texture still shows when rendered.

I read in the docs (maybe they may out of date docs, not sure) that glTexImage2D() takes in a TextureID as its last parameter however the glTexImage2D function I'm using does not. Has something changed and I haven't noticed it or is the above the correct way of texturing objects?

Thank you for the help,

Carl

thanks for the quick response, I will give that go.

Carl

*SOLVED*

QGLWidget has an overloaded function called bindTexture. The simplest way to use it is :



QGLWidget* ptr;

GLuint texId = ptr->bindTexture( QImage( filename ), GL_TEXTURE_2D );

// init everything else

// then in your render code

glBindTexture( GL_TEXTURE_2D, texId );






And everything works great! :D

Carl

[Edited by - ShabbaStoney on October 18, 2010 7:00:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
glTexImage2D is an initialization function. You call it once to load the texture to the Gfx Card.

......first code
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D()....


....render code
glBindTexture() ;//tells the gfx card to use this as the current texture

Share this post


Link to post
Share on other sites
Perhaps disable texturing when you don't need it glDisable(GL_TEXTURE_2D) and enable when you need it.

PS : I'm assuming you are not using shaders.

Share this post


Link to post
Share on other sites
Yeah I'll disable the textures when not needed. The main problem was getting the texture ID for each texture so I can have multiple textures. But I got it figured out :P

And yes not using shaders yet, always hated them but I'm determined to get my head around them.

Regards,

Carl

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!