KShots
12th July 2006, 23:00
Hello all...
I'm working a project where I have a QWorkspace containing many sub-classed QGLWidgets, and I'm running into problems. Before I get into those, I'd like to ask some generic questions (which may give me some insight on my below problems):
1. With multiple QGLContexts, will I need to bind the same textures to each QGLWidget to get the texture to show up, or do they share texture data?
Now, what I'm currently doing is loading the textures into OGL from my QMainWindow widget - not from any of my QGLWidgets. I am doing this because I want all current and future QGLWidgets to know about whatever textures I am loading. I can envision two scenarios if this is incorrect:
1. I need to go to at least one QGLWidget and load the texture, which all other current and future QGLWidgets would then know about
2. I need to go to all current QGLWidgets and load the texture, then all future QGLWidgets would need to load the texture(s) when they are initialized
Personally, I'd like to be able to do it externally to my QGLWidgets and be done with it.
With my current method, I load in my texture... but when I display it, I get a white model (no textures).
Here's what I'm doing. This first section is where I load in the texture:
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
int depth;
if(T.GetBPP() == 24)
{
depth = GL_RGB;
}
else
{
depth = GL_RGBA;
}
glTexImage2D(GL_TEXTURE_2D, 0, depth, T.GetWidth(), T.GetHeight(), 0, depth, GL_UNSIGNED_BYTE, T.GetData());As I'm just trying to make the thing "work" for now, I've simplified it - it's not really very usable beyond one texture.
texture - This holds my unique texture ID. I make sure it is unique through the use of glGenTextures()
T - This is a texture class I use... it decoded a bitmap file and holds the important data from it (I'd rather use this than the Qt equivalent loader for this application. I've checked that it has valid data).
I have glEnable(GL_TEXTURE_2D) in my initializeGL() function
That covers the loading of the texture. Now when I draw the model:
...
const Triangle * T = &TT->GetOList()[i]->GetConst();
assert(T);
if(T->GetTextureNumber() != 0xFFFFFFFF)
{
glBindTexture(GL_TEXTURE_2D, T->GetTextureNumber());
}
glBegin(GL_TRIANGLES);
for(char j = 0; j < 3; j++)
{
if(renderMode == GL_RENDER)
{
//glColor3ubv(!j?Yellow:j==1?Red:Green);
if(T->GetTextureNumber() != 0xFFFFFFFF)
{
glTexCoord2fv((*T).GetTexture(j)->GetConst().GetFloatStyle());
}
}
glNormal3fv((*T)[j].GetNormal().GetFloatStyle());
glVertex4fv((*T)[j].GetConst().GetFloatStyle());
}
glEnd();
...I tried to display just the interesting portion of the draw code... basically, for each triangle, I do textures, then normals, then the vertex. I bind the texture before the glBegin() function.
I'm starting to run out of ideas on what I'm missing :(
I'm working a project where I have a QWorkspace containing many sub-classed QGLWidgets, and I'm running into problems. Before I get into those, I'd like to ask some generic questions (which may give me some insight on my below problems):
1. With multiple QGLContexts, will I need to bind the same textures to each QGLWidget to get the texture to show up, or do they share texture data?
Now, what I'm currently doing is loading the textures into OGL from my QMainWindow widget - not from any of my QGLWidgets. I am doing this because I want all current and future QGLWidgets to know about whatever textures I am loading. I can envision two scenarios if this is incorrect:
1. I need to go to at least one QGLWidget and load the texture, which all other current and future QGLWidgets would then know about
2. I need to go to all current QGLWidgets and load the texture, then all future QGLWidgets would need to load the texture(s) when they are initialized
Personally, I'd like to be able to do it externally to my QGLWidgets and be done with it.
With my current method, I load in my texture... but when I display it, I get a white model (no textures).
Here's what I'm doing. This first section is where I load in the texture:
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
int depth;
if(T.GetBPP() == 24)
{
depth = GL_RGB;
}
else
{
depth = GL_RGBA;
}
glTexImage2D(GL_TEXTURE_2D, 0, depth, T.GetWidth(), T.GetHeight(), 0, depth, GL_UNSIGNED_BYTE, T.GetData());As I'm just trying to make the thing "work" for now, I've simplified it - it's not really very usable beyond one texture.
texture - This holds my unique texture ID. I make sure it is unique through the use of glGenTextures()
T - This is a texture class I use... it decoded a bitmap file and holds the important data from it (I'd rather use this than the Qt equivalent loader for this application. I've checked that it has valid data).
I have glEnable(GL_TEXTURE_2D) in my initializeGL() function
That covers the loading of the texture. Now when I draw the model:
...
const Triangle * T = &TT->GetOList()[i]->GetConst();
assert(T);
if(T->GetTextureNumber() != 0xFFFFFFFF)
{
glBindTexture(GL_TEXTURE_2D, T->GetTextureNumber());
}
glBegin(GL_TRIANGLES);
for(char j = 0; j < 3; j++)
{
if(renderMode == GL_RENDER)
{
//glColor3ubv(!j?Yellow:j==1?Red:Green);
if(T->GetTextureNumber() != 0xFFFFFFFF)
{
glTexCoord2fv((*T).GetTexture(j)->GetConst().GetFloatStyle());
}
}
glNormal3fv((*T)[j].GetNormal().GetFloatStyle());
glVertex4fv((*T)[j].GetConst().GetFloatStyle());
}
glEnd();
...I tried to display just the interesting portion of the draw code... basically, for each triangle, I do textures, then normals, then the vertex. I bind the texture before the glBegin() function.
I'm starting to run out of ideas on what I'm missing :(