Jump to content
  • Advertisement
Sign in to follow this  
ZuperMan

OpenGL adding texturing to my engine

This topic is 4974 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

well, I have a nice little engine running that supports both D3D and OpenGL through a plugin .dll file, but I don't have many features in the engine yet mostly just plans and just started to write it I have coloring of my mesh and lighting working. But now I want to add texturing support altough I can't figure out a good way to handle them regardless of the API currently running.. so I need some advice.. firtst I thougth I have a basic CTexture class that has it all, but where to store the OpenGL texture ID then? and what about D3D I havn't looked into textures there yet.

Share this post


Link to post
Share on other sites
Advertisement

The way I do this is to just expose a CreateTexture function from my D3D/OpenGL
DLL. This function takes a structure which you pass in the texture data, size,
mip levels etc, internally you create the texture for the render API and then
return an ID for the texture - in my case a uint.

Works easily and retains API independance.

Share this post


Link to post
Share on other sites
In my engine I used a CTextureManager class, (its a Singleton) only one instance of the class can ever exist, and I use this to manage my textures.

If your using OpenGL, your just maintaining a list of unsigned ints. If you use Direct3D, you maintain a list of IDirect3DTexture9 pointers.

You can load the texture from file here or have a generic CTexture class do it for you, and have the CTexture class as a member function of the CTextureManager class.

Thats basically it! Thats how I done it anyway and it works fine.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You should create a interface class for your textures (a pure virtual class) from this you should derive a d3dtexture and a gltexture class implementing the pure virtual functions. The problem is that if either API exposes special features that you cannot imitate on the other those can not be part of your texture class.

Share this post


Link to post
Share on other sites
I probably wouldn't bother with the CTexture class. Does it expose enough methods to make it worthwhile?

I'd probably define a base ITextureManager interface with CreateTexture/LoadTexture commands that return an ID number. Implement that interface for D3D and OpenGL. Internally, they can use that ID number to look up the data they need in a list or tree or something.

Share this post


Link to post
Share on other sites
I was thinking about the texture manager class, and let the current API handle the texture managing and just leave a texture ID for the rest of the engine, this way I could implement a texturemanager well suited for just that API e.g. OpenGL :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!