Open GL - Texturas 3D en Open GL

 
Vista:
sin imagen de perfil
Val: 2
Ha aumentado su posición en 5 puestos en Open GL (en relación al último mes)
Gráfica de Open GL

Texturas 3D en Open GL

Publicado por Rene (1 intervención) el 11/06/2021 21:34:09
Hola colegas,
Usando OpenGL con C++, estoy tratando de añadir texturas a esferas (nodos) de un Grafo Orientado.
Las esferas están ubicadas en un plano 3D y se acercan, alejan y rotan en dependencia de los movimientos del mouse.
Resulta que las esferas se colorean con el color de la textura pero no muestran la textura completa (Que contiene el nombre del nodo u otra imagen).
Les pongo el código y la imagen que se muestra a ver si alguien me puede ayudar en este objetivo.
Gracias,
René

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
      // Aquí se pasa el nombre del fichero que contiene la textura.
      // Pueden ser varias llamadas en dependencia del tipo de nodo.
      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();
  }

Grapho
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder