Dies ist eine statische Kopie unseres alten Forums. Es sind keine Interaktionen möglich.
This is a static copy of our old forum. Interactions are not possible.

TheWanderer

Zuhörer

  • "TheWanderer" is male
  • "TheWanderer" started this thread

Posts: 2

Date of registration: Mar 30th 2004

Location: Passau

Occupation: Informatik mit Fremdsprachen

1

Tuesday, March 30th 2004, 3:29am

An alle OpenGL Experten (Texture Mapping)

Hi Leuts!

Ich hoffe, der Post past thematisch einigermassen hier rein. Ich habe vor vor ein paar Monaten mit C++ und OpenGL Programmierung angefangen und verzweifle nun seit ein paar Tagen an einem Problem mit Texture Mapping. Vielleicht kann mir jemmand sagen, wo mein Fehler liegt. Texture Mapping an sich habe ich verstanden und auch zum Laufen gebracht, wenn ich aber mehrere Texturen verwenden möchte stehe ich vor einem Problem: Und zwar möchte ich bei Programmstart diverse Texturen vorgenerieren und in einem Array ablegen, dass global im ganzen Programm verfügbar ist. Dazu lasse ich bei Programmstart in einer Methode eine Schleife laufen, die mir aus einer Textdatei die Pfade für die einzelnen verwendeten Bitmaps als Strings herausliest. In jedem Schritt wird dann ein bmp file geladen, in eine Textur umgewandelt und dann in dem besagten Array abgespeichert. Das seltsame ist nun aber, dass das gesamte Array am Ende der Prozedur komplett mit der zuletzt generierten Textur belegt ist, alle anderen Texturen also überschrieben wurden... ich kann's mir nicht erklären.


Die Methode, die das alle Bitmaps lädt und in Texturen umwandelt:

bool CModelViewer::GenerateGLTextures()
{
// Status Indicator
bool status = false;

// Creates a pointer to the ExiD3D main class
CExiD3DApp* theApp = (CExiD3DApp*) AfxGetApp();

// Creates a temporary storage space for the current texture
AUX_RGBImageRec *TextureImage[1];

// Sets the pointer to NULL
memset(TextureImage,0,sizeof(void *)*1);

int i = 0;
char buffer[256];
CString tmpTextureID;

ifstream textureSource("textures.dat");

theApp->m_iTextureSpaceUsed = 0;
while(!textureSource.eof())
{
tmpTextureID.Format("%i", i);
textureSource.getline(buffer, 100);
theApp->m_TextureID[0] = buffer;
theApp->m_TextureID[i][1] = tmpTextureID;
theApp->m_iTextureSpaceUsed++;
i++;
}

for (i = 0; i < theApp->m_iTextureSpaceUsed; i++)
{
// Loads bitmap, checks for errors, if bitmap was not found quit
if (TextureImage[0] = LoadBMP(theApp->m_TextureID[i][0]))
{
status = true;

// Creates the texture
glGenTextures(1, &(theApp->m_Textures[i]));

// Creates a linear filtered texture
glBindTexture(GL_TEXTURE_2D, theApp->m_Textures[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX,TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
}
}

// If a texture was successfully created and loaded to the image buffer
// the storage for it can be freed
if (TextureImage[0])
{
if (TextureImage[0]->data) // If texture image exists
{
free(TextureImage[0]->data); // Free texture image memory
}
free(TextureImage[0]); // Free image structure
}

return status;
}


Die Arrays, die ich zum Speichern der Texturen und der Dateinamen inklusive ihrer ID im Programm verwende:

// Texture information
int m_iTextures; // Number of supported textures by the program
int m_iTextureSpaceUsed; // Number of textures already used
CString m_TextureID[100][2]; // fileName and ID of the used textures
GLuint m_Textures[100]; // Storage for 100 textures


Und die Square.cpp class in der ich dann verschiedene Texturen verwenden will:

...
// Texture enabled
if (this->m_bTextureEnabled) {
glBegin(GL_QUADS);
// Binds a texture to the square
glBindTexture(GL_TEXTURE_2D, theApp->m_Textures[theApp->GetObjTextureID(this->m_strTexture)]);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(...


Ich weiss, der Code ist noch nicht wirklich ausgereift, aber er sollte erstmal funktionieren, bevor ich optimiere.
Verwenden tue ich das Microsoft Dev. Studio 6 für Visual C++.
Ich bin für jede Hilfe und jeden Ratschlag dankbar!

Grüsse,


Mark
Talente finden Lösungen - Genies entdecken Probleme!

T2k

Erfahrener Schreiberling

  • "T2k" is male

Posts: 339

Date of registration: Oct 9th 2002

Location: da drüben, gleich dort.

Occupation: Warum? Hmm, weil ich sonst nix mit meiner Zeit anzufangen weiß :D

2

Tuesday, March 30th 2004, 12:15pm

schonmal versucht glBindTexture vor glBegin zu benutzten? ansonsten ist es immer sinnvoll glGetError() zu verwenden, dann weiss man wenigstens wo der Fehler auftritt :D

aus MSDN

Quoted

The parameter texture did not have the same dimensionality as target, or the glBindTexture functions was called between a call to glBegin and the corresponding call to glEnd.



T2k
Die zweithäufigste Todesursache eines Soldaten ist das Gewicht seines Rückentornisters ("http://olnigg.de/" Aug05/Nr120)

TheWanderer

Zuhörer

  • "TheWanderer" is male
  • "TheWanderer" started this thread

Posts: 2

Date of registration: Mar 30th 2004

Location: Passau

Occupation: Informatik mit Fremdsprachen

3

Tuesday, March 30th 2004, 9:17pm

Vielen Dank!

Oh man, das ist mal wieder ein Fall von den Wald vor lauter Bäumen nicht sehen! Argh! :P
Hey vielen Dank für deine Hilfe und die prompte Antwort!
Schönen Tag noch,


Mark :)
Talente finden Lösungen - Genies entdecken Probleme!