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("
");
glPushClientAttrib(0);
if (this->Colors != NULL)
{
glEnableClientState(GL_COLOR_ARRAY);
printf("%d %d %d
" ,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 && this->Indices != NULL)
{
glEnableClientState(GL_VERTEX_ARRAY);
printf("%d %d %d
" ,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("
");
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,&(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 :
[ul][li]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[/ul][/li]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