Hey guys,
I am trying to read in a photoshop .raw file and use its data to create an OpenGl texture. Here is the code I have at the minute
GLuint _texture;
LoadTestTexture(int width, int height, string fileName) {
BYTE * data = new BYTE[width * height * 3];
FILE * file;
//read texture data
fopen_s(&file, fileName.c_str(), "rb");
fread(data, width * height * 3, 1, file);
fclose(file);
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_2D, _texture);
// elect modulate to mix texture with color for shading
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//when texture area is small, bilinear filter the closest mipmap
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
// when texture area is large, bilinear filter the first mipmap
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//the texture wraps over at the edges
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_BYTE, data);
//build texture mipmaps
//gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_BYTE, data);
}
However, when I go to draw the texture there only seems to be a red square appearing. I looked into what values were being extracted from the .raw file, and they were along the lines of 255, 157, 38 etc ie They weren’t all 255 (which would explain the solid red texture).
The image file is a white image with black lines drawn over it. Does anyone have any ideas what I’m doing wrong? Thanks in advance!