Archived

This topic is now archived and is closed to further replies.

Texture class problem

This topic is 5502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have enclosed my texture objects in a class for easy management. for some reason the function that loads the bitmap won''t work when called from the constructor of another class. i got around this pretty easy but on another project the texture would only work when it was loaded from the member function that did the drawing.This is a character model class that it''s being used on by the way. here it is. #ifndef TexturesH #define TexturesH #include <windows.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> #include <fstream.h> #include <LeeLib\NewString.h> //--------------------------------------------------------------------------- class Textures { protected: NewString TexFilename; GLuint TexName; bool TexActive; bool TexEmpty; int TexHeight; int TexWidth; int TexDepth; int TexSize; int TexPixels; public: Textures(); void Bind(); // Creation bool LoadFromBMP(char* Filename); // Delete void Free(); void SetFilename(char* filename); // Return Functions char* Filename(); GLuint Name(); bool Active(); bool Empty(); int Height(); int Width(); int Depth(); int Size(); int Pixels(); }; #endif ================================================================ #include <vcl.h> #pragma hdrstop #include "Leelib\Textures.h" #pragma package(smart_init) //============================================================== Textures::Textures() { TexEmpty=TRUE; } //============================================================== void Textures::Bind() { glBindTexture(GL_TEXTURE_2D,TexName); } //============================================================== bool Textures::LoadFromBMP(char* Filename) { AUX_RGBImageRec *TexImage; FILE *File; if(Filename[0] == NULL) return FALSE; File=fopen(Filename,"r"); if (File) { fclose(File); TexImage=auxDIBImageLoad(Filename); glGenTextures(1, &TexName); glBindTexture(GL_TEXTURE_2D, TexName); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TexImage->sizeX, TexImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TexImage->data); } else return FALSE; TexEmpty=FALSE; TexHeight=TexImage->sizeY; TexWidth=TexImage->sizeX; TexDepth=3; TexPixels=TexHeight*TexWidth; TexSize=TexPixels*12; TexFilename.SetString(Filename); return TRUE; } //============================================================== void Textures::Free() { //glDeleteTextures(1,Name); TexFilename.Clear(); TexActive=FALSE; TexEmpty=TRUE; TexHeight=0; TexWidth=0; TexDepth=0; TexPixels=0; TexSize=0; } //============================================================== void Textures::SetFilename(char* filename) { TexFilename.SetString(filename); } //============================================================== char* Textures::Filename() { if(TexFilename.IsEmpty()) return NULL; return TexFilename.Contents(); } //============================================================== GLuint Textures::Name() { return TexName; } //============================================================== bool Textures::Active() { return TexActive; } //============================================================== bool Textures::Empty() { return TexEmpty; } //============================================================== int Textures::Height() { return TexHeight; } //============================================================== int Textures::Width() { return TexWidth; } //============================================================== int Textures::Depth() { return TexDepth; } //============================================================== int Textures::Size() { return TexSize; } //============================================================== int Textures:ixels() { return TexPixels; } //==============================================================

Share this post


Link to post
Share on other sites
you can''t load texutres when an opengl window/context has not been setup (this may be your problem here).

what is always really useful with texture objects like this is if you keep a static list of them all, then you can just have single functions along the lines of reloadAll() which you can call when you, say, change from full screen to windowed, without any hassle at all... (you could also call this when the app is first created, so all textures that couldn''t be loaded when there wasn''t a GL context can be loaded then, or such)

btw. just juding from your code there, I''m guessing you putting a load of headers into every single other header/class file... This is exactly the situation pre compiled headers (eg, stdafx.h) are designed to help, they make code much cleaner and compile a hang of a lot faster... so you might want to look into them (get VC to create a basic win32 wizard app and it will have stdafx.h/cpp automatically) for example.

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

Share this post


Link to post
Share on other sites
the line that loads the textures is the last line in the section
that creates the window so i''m pretty sure everything is set up at this point.

p.s. do you know where i might find instructions for those
precompiled headers for c++ builder5?

Share this post


Link to post
Share on other sites