He,
Using OpenGL with C++, I am trying to add textures to spheres (nodes) of an Oriented Graph.
The spheres are located in a 3D plane and zoom in, zoom out and rotate depending on mouse movements.
It turns out that the spheres are colored with the color of the texture but they do not show the complete texture (which contains the name of the node or another image).
I put the code and the image that is shown to see if someone can help me in this objective.
Thank,
René
void __fastcall TForm2::LoadTextures(AnsiString nomfile)
{
int x,y;
GLuint texture;
bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile(nomfile);
x=bitmap->Width;
y=bitmap->Height;
GLubyte bits[200][200][4];
for(int i = 0; i < x; i++)
{
for(int j = 0; j < y; j++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][3]= (GLbyte)255;
}
}
glColor3f(255,255,255);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
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_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
}
void TForm2::DibujarEquipos(int pieza)
{
glPushMatrix();
for (int x = 0; x < conexiones->Get_cant_equipos() ; x++)
{
glPushMatrix();
glColor3f(1.0f, 1.0f, 1.0f);
.
//Here the name of the file containing the texture is passed as a parameter.
//There can be several calls depending on the type of node.
LoadTextures("texturefile.bmp");
glTranslated(conexiones->Get_coordenadas()[pieza][x][0] , conexiones->Get_coordenadas()[pieza][x][1] ,conexiones->Get_coordenadas()[pieza][x][2]);
gluSphere(quadratic , 0.5 , 32 , 32);
glPopMatrix();
}
glPopMatrix();
}