PDA

View Full Version : vertex array and texture : no texture displayed



jean-luc
01-29-2010, 01:57 PM
Hi!
I'm new to OpenGl, I'm coding a C++ application using vertex array (seemed to be a good idea at first)
the main opengl class is called VertexObject that contain all the information to display (vertexarray, normalarray, colorarray and texture) and there is another class called Texture that hold the texture information and the texture coordinates.

I construct a Vertex object with the following code

rectangleTextureVO = new VertexObject();
GLfloat Vertices3[4][3] = { { 0.0, 0.0, 0.0}, //0
{ w, 0.0, 0.0}, //1
{ w, h, 0.0}, //2
{ 0.0, h, 0.0}};//3
rectangleTextureVO->SetVerticesArray(DataArray::FLOAT, 3, Vertices3, 4);
GLubyte indices3[] = {0, 1, 2, 3};
rectangleTextureVO->SetFaceIndicesArray(DataArray::UINT8_T, 4, indices, 1);

NCRC_AutoPtr<Texture> texture3(new PPMTexture(texturename));
GLint TexCoord3[4][2] = { { 0 , 0 }, // 0
{ texture3->Width(), 0 }, //1
{ texture3->Width(), texture3->Height() }, //2
{ 0 , texture3->Height() } //3
};
NCRC_AutoPtr<DataArray> texcoord3(new DataArray(4, 2, DataArray::FLOAT, TexCoord3));
texture3->SetTexCoord(texcoord3);
rectangleTextureVO->AddTexture(texture3);
//rectangleTextureVO->SetColorArray(colors);
as you see this is a rectangle with a texture on it
the drawing function is as follow

int VertexObject::draw()
{
IN("\n");
glPushClientAttrib(0);

if (this->Colors != NULL)
{
glEnableClientState(GL_COLOR_ARRAY);
printf("%d %d %d\n" ,Colors->ComponentsCount, Colors->datatype_t, Colors->array.all);
glColorPointer(Colors->ComponentsCount, Colors->datatype_t, 0, Colors->array.all);
}
if (this->Normals != NULL)
{
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(Normals->datatype_t, 0, Normals->array.all);
}
if (this->TextureData != NULL)
{
this->TextureData->ClientActiveTexture(GL_TEXTURE0);


}
if (this->Vertices != NULL &amp;&amp; this->Indices != NULL)
{
glEnableClientState(GL_VERTEX_ARRAY);
printf("%d %d %d\n" ,Vertices->ComponentsCount, Vertices->datatype_t, Vertices->array.all);
glVertexPointer(Vertices->ComponentsCount, Vertices->datatype_t, 0, Vertices->array.all);
//go through our index array and draw our vertex array
GLenum mode;
if ( Indices->ComponentsCount == 3 ) mode = GL_TRIANGLES;
else mode = GL_QUADS;

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT, GL_SHININESS, high_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);


//Indices->count has allready the right count of Indices (Indices->ComponentsCount*nbfaces)
glDrawElements(mode,
this->Indices->count * this->Indices->ComponentsCount,
this->Indices->datatype_t,
this->Indices->array.all);
}
if (this->TextureData != NULL)
{
this->TextureData->ReleaseTecture();
}

glPopClientAttrib();

debug::Instance()->FlushGL();
OUT("\n");
return 0;
}as you see in the VertexObject draw() method according to the content of the vertex object I'm activating the gl's features
now remain the texture activation part (the this->TextureData->ClientActiveTexture(GL_TEXTURE0);)


int Texture::Finalise()
{
glEnable( TextureType );

glTexImage2D (
TextureType,
0,
this->ComponentsCount,
this->width,
this->height,
0,
this->format,
this->type,
pdata
);
glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture( TextureType, ID);
}


void Texture::ClientActiveTexture( GLenum texture )
{
texturePipeID = texture;
glActiveTextureARB( texturePipeID );
glClientActiveTexture(texturePipeID);
glEnable( TextureType );

if (ID == 0)
{
glGenTextures(1,&amp;(this->ID));
Finalise();
}
//glDisable( GL_BLEND );
glBindTexture(TextureType,ID);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(TexCoord->ComponentsCount,
(GLenum)*(TexCoord),
0,
TexCoord->array.all);

}
since I can't generate the ID in constructor of the object because the OpenGl context isn't set, I do it by detecting that ID is null

the problem is the following :

when I use a color array, the output is correct (a rectangle with the correct colors) When I use no color array and activate the texture, I get a blank rectangle
I looked the web for texturing with vertex array, got several answer on VBO, a few (including this wiki) on vertex array, and about 3 interesting posts on other forums, even in an opengl book found on google books didn't helped. All I know is that the
glActiveTextureARB( texturePipeID );
glClientActiveTexture(texturePipeID); have to be actived for each texture in case of multitexturing before any operation on the texture can be performed.....
I'll really be thanks-full for any help
Best Regards
JLM

jean-luc
02-01-2010, 03:48 AM
about textures : I forgot to precise the following :


this->type = GL_UNSIGNED_BYTE;
this->width = 200;
this->height = 92;
this->ComponentsCount = 3;
this->TextureType = GL_TEXTURE_2D;
this->format = GL_RGB

jean-luc
02-01-2010, 06:16 AM
I found a way to create the opengl call log using gDEBugger :


glXChooseFBConfig(0x080D1E18, 0, 0x0807A280, 0xBFFFEE6C)
glXGetVisualFromFBConfig(0x080D1E18, 0x080DF5F8)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF5F8, GLX_SAMPLE_BUFFERS, 0xBFFFEE50)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF5F8, GLX_SAMPLES, 0xBFFFEE4C)
glXGetVisualFromFBConfig(0x080D1E18, 0x080DF7A8)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF7A8, GLX_SAMPLE_BUFFERS, 0xBFFFEE50)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF7A8, GLX_SAMPLES, 0xBFFFEE4C)
glXGetVisualFromFBConfig(0x080D1E18, 0x080DF6D0)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF6D0, GLX_SAMPLE_BUFFERS, 0xBFFFEE50)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF6D0, GLX_SAMPLES, 0xBFFFEE4C)
glXGetVisualFromFBConfig(0x080D1E18, 0x080DF880)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF880, GLX_SAMPLE_BUFFERS, 0xBFFFEE50)
glXGetFBConfigAttrib(0x080D1E18, 0x080DF880, GLX_SAMPLES, 0xBFFFEE4C)
glXGetVisualFromFBConfig(0x080D1E18, 0x080DF5F8)
glXGetProcAddress(glXCreateContextAttribsARB)
glXGetVisualFromFBConfig(0x080D1E18, 0x080DF5F8)
glXCreateContext(0x080D1E18, 0x080A20A0, 0x00000000, True)
glXIsDirect(0x080D1E18, 0x080A22E8)
glXMakeCurrent(0x080D1E18, 85983234, 0x080A22E8)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_NORMALIZE)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glShadeModel(GL_SMOOTH)
glViewport(0, 0, 200, 200)
glGetIntegerv(GL_DRAW_BUFFER, 0xB748AE6C)
glDrawBuffer(GL_FRONT)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glTranslatef(6, 6, -1000)
glLoadIdentity()
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, 212, 0, 212, -1000, 1000)
glMatrixMode(GL_MODELVIEW)
glTranslatef(0, 0, -999)
glLoadIdentity()
glTranslatef(60, 40, -60)
glRotatef(45, 1, 1, 1)
glPushClientAttrib(0x0)
glActiveTextureARB(GL_TEXTURE0)
glClientActiveTexture(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D)
glGenTextures(1, {0})
glEnable(GL_TEXTURE_2D)
glTexImage2D(GL_TEXTURE_2D, 0, 3, 200, 92, 0, GL_RGB, GL_UNSIGNED_BYTE, 0xB751C008)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glBindTexture(GL_TEXTURE_2D, 1)
glBindTexture(GL_TEXTURE_2D, 1)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glTexCoordPointer(2, GL_FLOAT, 0, 0x080A21D0)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3, GL_FLOAT, 0, 0x080E7DF0)
glMaterialfv(GL_FRONT, GL_AMBIENT, {0.1, 0, 0, 0})
glMaterialfv(GL_FRONT, GL_DIFFUSE, {0.1, 0, 0, 0})
glMaterialfv(GL_FRONT, GL_SPECULAR, {1, 0, 0, 0})
glMaterialf(GL_FRONT, GL_SHININESS, 100)
glMaterialfv(GL_FRONT, GL_EMISSION, {0, 1.4719769e+19, 1.5301056e+19, 1.7750774e+28})
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, 0x080E7E70)
glActiveTextureARB(GL_TEXTURE0)
glDisable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, 0)
glPopClientAttrib()
glFlush()
glLoadIdentity()
glTranslatef(20, 10, -60)
glRotatef(45, 1, 1, 1)
glPushClientAttrib(0x0)
glEnableClientState(GL_COLOR_ARRAY)
glColorPointer(3, GL_FLOAT, 0, 0x080E8060)
glEnableClientState(GL_NORMAL_ARRAY)
glNormalPointer(GL_FLOAT, 0, 0x080E80E0)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3, GL_FLOAT, 0, 0x080E7FA8)
glMaterialfv(GL_FRONT, GL_AMBIENT, {0.1, nan, nan, nan})
glMaterialfv(GL_FRONT, GL_DIFFUSE, {0.1, nan, nan, nan})
glMaterialfv(GL_FRONT, GL_SPECULAR, {1, nan, nan, nan})
glMaterialf(GL_FRONT, GL_SHININESS, 100)
glMaterialfv(GL_FRONT, GL_EMISSION, {0, nan, nan, nan})
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, 0x080E8028)
glPopClientAttrib()
glFlush()
glLoadIdentity()
glTranslatef(100, 100, -60)
glRotatef(45, 1, 1, 1)
glPushClientAttrib(0x0)
glActiveTextureARB(GL_TEXTURE0)
glClientActiveTexture(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D)
glGenTextures(1, {0})
glEnable(GL_TEXTURE_2D)
glTexImage2D(GL_TEXTURE_2D, 0, 3, 200, 92, 0, GL_RGB, GL_UNSIGNED_BYTE, 0xB748C008)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glBindTexture(GL_TEXTURE_2D, 2)
glBindTexture(GL_TEXTURE_2D, 2)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glTexCoordPointer(2, GL_FLOAT, 0, 0x080E3A78)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3, GL_FLOAT, 0, 0x080E5350)
glMaterialfv(GL_FRONT, GL_AMBIENT, {0.1, nan, nan, 1.209741e-41})
glMaterialfv(GL_FRONT, GL_DIFFUSE, {0.1, 9.2537939e-39, 0, 0})
glMaterialfv(GL_FRONT, GL_SPECULAR, {1, 1.2063778e-41, 9.2537939e-39, 9.2537939e-39})
glMaterialf(GL_FRONT, GL_SHININESS, 100)
glMaterialfv(GL_FRONT, GL_EMISSION, {0, nan, nan, nan})
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, 0x080E38B0)
glActiveTextureARB(GL_TEXTURE0)
glDisable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, 0)
glPopClientAttrib()
glFlush()
glPopMatrix()
glFlush()

it's a complete execution log, including context creation and 3 VA creation and display (1 is non textured, 2nd is a textured cube, 3 is the textured rectangle, no textures are displayed at all)
what is strange is that gDEBugger doesn't report any texture....

jean-luc
02-02-2010, 07:58 AM
Hi! still replying to myself...
I managed to fix some issues in my code and use gDEBugger more accuratly,
one thing that troubled gDEBugger was that the context was created in another thread than the rendering one... now that the context is created in the same thread than the rendering one, gDEBugger is able to retrieve my textures from the graphic card.
-> the textures are correct

I breaked on glDrawElements, at this stage gDEBugger tells me that "Texture1 (unit0, bound 2D) - Enabled"
and in advanced details :
[CODE]
Texture 1
General
Type 2D Texture
#-of-Mipmaps 1 Level(s)
Dimensions 200x92
Border-Width 0px
Internal Pixel Format
Requested 3
Used 3
Pixel Format
Format GL_RGB
Type GL_UNSIGNED_BYTE
Texture Parameters
Name Value
GL_TEXTURE_MIN_FILTER GL_LINEAR
GL_TEXTURE_MAG_FILTER GL_LINEAR
GL_TEXTURE_WRAP_S GL_REPEAT
GL_TEXTURE_WRAP_T GL_REPEAT
GL_TEXTURE_WRAP_R GL_REPEAT
GL_TEXTURE_MIN_LOD -1000
GL_TEXTURE_MAX_LOD 1000
GL_TEXTURE_BASE_LEVEL 0
GL_TEXTURE_MAX_LEVEL 1000
GL_GENERATE_MIPMAP FALSE
GL_TEXTURE_PRIORITY 1
GL_TEXTURE_BORDER_COLOR {0, 0, 0, 0}
GL_TEXTURE_RESIDENT TRUE
GL_TEXTURE_COMPARE_MODE 0
GL_TEXTURE_COMPARE_FUNC GL_LEQUAL
GL_DEPTH_TEXTURE_MODE GL_LUMINANCE
Level 0 Parameters
Name Value
GL_TEXTURE_WIDTH 200
GL_TEXTURE_HEIGHT 92
GL_TEXTURE_DEPTH 1
GL_TEXTURE_INTERNAL_FORMAT GL_LINE_STRIP
GL_TEXTURE_BORDER 0
GL_TEXTURE_RED_SIZE 8
GL_TEXTURE_GREEN_SIZE 8
GL_TEXTURE_BLUE_SIZE 8
GL_TEXTURE_ALPHA_SIZE 0
GL_TEXTURE_LUMINANCE_SIZE 0
GL_TEXTURE_INTENSITY_SIZE 0
GL_TEXTURE_DEPTH_SIZE 0
GL_TEXTURE_SHARED_SIZE N/A
GL_TEXTURE_STENCIL_SIZE 0
GL_TEXTURE_COMPRESSED FALSE
GL_TEXTURE_COMPRESSED_IMAGE_SIZE N/A
GL_TEXTURE_RED_TYPE N/A
GL_TEXTURE_GREEN_TYPE N/A
GL_TEXTURE_BLUE_TYPE N/A
GL_TEXTURE_ALPHA_TYPE N/A
GL_TEXTURE_DEPTH_TYPE N/A
GL_TEXTURE_SAMPLES N/A
GL_TEXTURE_FIXED_SAMPLE_LOCATIONS N/A
GL_TEXTURE_HI_SIZE_NV N/A
GL_TEXTURE_LO_SIZE_NV N/A
GL_TEXTURE_DS_SIZE_NV N/A
GL_TEXTURE_DT_SIZE_NV N/A
GL_TEXTURE_MAG_SIZE_NV N/A
[\code]

jean-luc
02-03-2010, 08:02 AM
the error was here (appart the fact that the context wasn't created in the same thread)


GLint TexCoord3[4][2] = { { 0 , 0 }, // 0
{ texture3->Width(), 0 }, //1
{ texture3->Width(), texture3->Height() }, //2
{ 0 , texture3->Height() } //3
};
NCRC_AutoPtr<DataArray> texcoord3(new DataArray(4, 2, DataArray::FLOAT, TexCoord3));

which cause the following opengl call glTexCoordPointer(2, GL_FLOAT, 0, 0x080A21D0)

yes the array is an int array... but I was telling opengl it was float...
I have my texture now
JLM