I m having issues trying to get a texture loaded into VRAM. I m using OpenGL on Mac OS X. I have geometry that I ve successfully renderer by passing a color into my fragment shader. However, as soon as I try to load a texture, no geometry gets rendered and I can only see the background color. Here s my texture loading code:
char imageData[27] = {
127, 127, 127,
127, 127, 127,
127, 127, 127,
127, 127, 127,
127, 127, 127,
127, 127, 127,
127, 127, 127,
127, 127, 127,
127, 127, 127,
};
glActiveTexture(GL_TEXTURE0);
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 3, 3, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
GLint uniform_location = glGetUniformLocation(bundle->GetShaderProgramID(), "texture");
std::cout << uniform_location <<std::endl;
glUniform1i(uniform_location, 0);
glEnable(GL_TEXTURE_2D);
And here s my fragment shader code:
uniform sampler2D texture;
void main()
{
vec2 coord = vec2(0.5, 0.5);
//gl_FragColor = vec4(coord, 0.0, 1.0);
gl_FragColor = vec4(texture2D(texture, coord).rgb, 1.0);
}
I realize some of this code probably isn t necessary, but I ve been trying everything I can think of.
Thanks.