2

I use openGL´s SOIL to load images and SOIL_load_image() returns an unsigned char*, which is then used by openGL to color all the width*height pixels.

I would like to be able to pass my own unsigned char* to represent one single color. How do I represent color in a string/char*?

This is what I am thinking about:

GLuint createTextureID(std::string texturePath) {

    int width, height;
    GLuint texID = 0;
    unsigned char* texData = nullptr;

    //currently, all my file paths begin with "..//"
    if (texturePath.at(0) != '.')
    {
        texData = texturePath.c_str();
        width = 1;
        height = 1;
    }
    else
    {
        texData = SOIL_load_image(texturePath.c_str(), &width, &height, 0, SOIL_LOAD_RGBA);
    }

    //UPLOAD texData TO OPENGL
}
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
stimulate
  • 1,199
  • 1
  • 11
  • 30
  • It probably is a pointer to an unsigned char array with three (RGB) or four (RGBA) entries. You'll have to find out the order of the color channels in the array. – RhinoDevel Oct 21 '16 at 16:23
  • How do i do that? when i check the pointer to the data with a breakpoint it only contains cryptic characters ("Ãľÿª«¥ÿŸ šÿ•–ÿ....") – stimulate Oct 21 '16 at 16:27
  • In C and C++ `unsigned char` is essentially an unsigned byte. Therefore the pointer you have points to a memory region of bytes. The layout of pixels on that buffer varies from format to format. For example, Windows bitmaps are stored on (1-byte Blue, 1-byte Green, 1-Byte Red) components aligned on a multiple of 4 line of pixels. – zahir Oct 21 '16 at 16:29
  • could you be a little bit more explicit? what do you mean with "es"? – stimulate Oct 21 '16 at 16:31
  • 1
    Load three bitmaps, one each of pure red, pure green, and pure blue. As you do, look at the integer values in the `char`s its pointer leads to. Chances are good that you'll see patterns of `255, 0, 0`, `0, 0, 255`, and `0, 255, 0`. Look at which color gives a 255 and which position, and you'll know the order in which it expects the colors. – Jerry Coffin Oct 21 '16 at 16:34
  • thanks, it finally works. dealing with strings and char* is somewhat of a pain, i think i need a recap on that – stimulate Oct 21 '16 at 17:48

0 Answers0