Jump to content
  • Advertisement
Sign in to follow this  
melog625

OpenGL Texture questions

This topic is 3797 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 in my code a class texture class Texture{ vector<vector<Color> > Color_Array; } Is there a way to take this array and turn it into an openGL texture? Im very new to openGL, so forgive me if this is an obvious question.

Share this post


Link to post
Share on other sites
Advertisement
There's some code here that creates a texture procedurally. You should be able to modify it to do what you want.

Share this post


Link to post
Share on other sites
OpenGL generates textures from an array of primitives, e.g. 256*256*3 bytes for a 256 square RGB 8bit texture. There are several formats and types OpenGL can work with, see e.g. glTexImage2D for details. Hence you can use your structure as long as it can return / be casted into one of OpenGL's formats. Otherwise you'll need an explicit conversion.

Share this post


Link to post
Share on other sites
Quote:
Original post by melog625
class Texture{
vector<vector<Color> > Color_Array;
}


Don't use std::vector for things like that. Just allocate an array on the heap.




Here's some code from my own OpenGL Texture class.
It uses Corona, but you should be able to work around that.


//
// Texture.h
//

class Texture
{
public:
int Width (void) const;
int Height (void) const;

Texture (char* file, int internalformat);
~Texture (void);

void SetFilters (int min, int mag);
void SetWrapMode (int s, int t);

unsigned int GetObjHandle (void) const;

private:
int width, height;
unsigned int objhandle;
};






//
// Texture.cpp
//

Texture::Texture (char* file, int internalformat)
{
unsigned char* contents;

// Make texture object
glGenTextures(1, &objhandle);
glBindTexture(GL_TEXTURE_2D, objhandle);


// Load image data from file
corona::Image* image = corona::OpenImage(file, corona::PF_R8G8B8A8);
if (!image)
{
AddFileError(file, "Texture::Texture");
return;
}
FlipImage(image, 1);
contents = (unsigned char*) image->getPixels();

// Upload image data to OpenGL
width = image->getWidth();
height = image->getHeight();
glTexImage2D(GL_TEXTURE_2D,
0,
internalformat,
width,
height,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
contents);

// Delete Corona image object (it's just temporary)
delete image;
}



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!