Komputerowiec Posted June 6, 2009 Report Share Posted June 6, 2009 Elo. Mam problem dotyczacy textur. Pokaze spory kawalek kodu, bo inaczej sie nie polapiecie . No wiec mam taki kod: typedef struct _bitmapFile { int width, height; unsigned char *data; } bitmapFile; class CTexture { public: CTexture(){} ~CTexture(){} void SetupAndLoadTexture(char *filename, bitmapFile *bitmap); void freeBitmapFile(bitmapFile *bitmap); void loadBitmapFromFile(char *fileName,bitmapFile *bitmap); void ChooseTex(){glBindTexture(GL_TEXTURE_2D, texture);} int GetTex(){return texture;} private: int texture; }; void CTexture::loadBitmapFromFile(char *fileName,bitmapFile *bitmap) { FILE *file; int bitmapSize; int i; file = fopen(fileName, "rb"); if (!file) return; fseek(file, 18, SEEK_SET); fread(&bitmap->width, 4, 1, file); fseek(file, 22, SEEK_SET); fread(&bitmap->height, 4, 1, file); fseek(file, 34, SEEK_SET); fread(&bitmapSize, 4, 1, file); bitmap->data = new unsigned char[bitmapSize]; fseek(file, 54, SEEK_SET); fread(bitmap->data, bitmapSize, 1, file); for (i = 0; i < bitmapSize; i += 3) { int tempByte = bitmap->data[i]; bitmap->data[i] = bitmap->data[i+2]; bitmap->data[i+2] = tempByte; } fclose(file); } void CTexture::freeBitmapFile(bitmapFile *bitmap) { if (bitmap->data != NULL) { delete[] bitmap->data; bitmap->data = NULL; } } void CTexture::SetupAndLoadTexture(char *filename, bitmapFile *bitmap) { loadBitmapFromFile(filename, bitmap); glGenTextures(1, (GLuint*)&texture); glBindTexture(GL_TEXTURE_2D, texture); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, bitmap->width, bitmap->height, GL_RGB, GL_UNSIGNED_BYTE, bitmap->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); } No i gdy laduje sobie texture funkcja SetupAndLoadTexture(...) wszystko jest dobrze, ale gdy laduje 2 textury, to wyswietla mi sie tylko ta textura, ktora byla zaladowana jako ostatnia ;/. Ktos moze wie dlaczego? Z gory THX. Link to comment Share on other sites More sharing options...
Blind Posted June 6, 2009 Report Share Posted June 6, 2009 bo ustawiasz aktywna teksture na ta ktora byla zaladowana jako ostatnia? co ty chcesz w ogole zrobic? www.blinder.pl - Blog Link to comment Share on other sites More sharing options...
Komputerowiec Posted June 6, 2009 Author Report Share Posted June 6, 2009 Chce zrobic normalna klase textur, popatrz na to: void renderTexturedCube() { glBegin(GL_QUADS); glBindTexture(GL_TEXTURE_2D, test.GetTex()); test.ChooseTex(); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glBindTexture(GL_TEXTURE_2D, test2.GetTex()); test2.ChooseTex(); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glEnd(); } Probuje wybrac texture na wszystkie sposoby, ale sie nie udaje ;p. Link to comment Share on other sites More sharing options...
5corpio Posted June 6, 2009 Report Share Posted June 6, 2009 O ile jeszcze pamiętam coś to bindowanie tekstur nie działa pomiędzy glBegin() i glEnd() dlatego masz błąd... Poprostu jakoś tak było z maszyną stanów OGl-a i kartą graficzną, że albo się zmienia stany albo jest przełączone renderowanie... dokładnie nie wiem/pamiętam. W każdym bądź razie musisz zbindowac teksturę potem wyrenderować wszystko i znowu bind tekstury i kolejny glBegin i glEnd i wtedy śmiga bo w tej klasie do wczytywania tekstur nie powinno być problemów. Ot taka mini-strona moja po godzinach http://www.wnetrzekuchni.pl Link to comment Share on other sites More sharing options...
Komputerowiec Posted June 7, 2009 Author Report Share Posted June 7, 2009 Ok, dzieki scorpio teraz dziala . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.