Creating Opengl texture from byte array

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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!
Last edited on
I'm posting this as a follow up, because everyone hates the guy who just abandons his own help thread when he gets the problem solved.

I'm not sure how I fixed this to be honest. I gave up and went on to other things until today, when I started a new project. The code is mostly the same except it is in a new project.

Upon drawing the scene I see a white texture, which is more like the image I was hoping to display. When I moved the camera back the correct white image with black lines appeared for me.

So, if anyone out there is having a similar sort of issue, try moving the camera out a bit to see what you can see.
Topic archived. No new replies allowed.