Textures come up black when using a gl 3.3 context

Started by
3 comments, last by andrew111 13 years, 5 months ago
Hi,

I'm trying to draw a triangle with a texture mapped to it (using only a shader program, vertex buffers, a uniform buffer, etc so no immediate mode) in the gl context 3.3, but the triangle is rendered black. Though if I use the gl context 3.1, the texture draws fine.

So the first thing that I thought might be a problem was my shader code, and I was hoping someone could check if I am missing anything, shown below, so I can rule it out.

vertex shader:
#version 330layout(std140, row_major) uniform u_transform {mat4 modelViewProj;};in vec3 a_pos;in vec2 a_tex;varying vec2 v_tex;void main() {	v_tex = a_tex;	gl_Position = modelViewProj*vec4(a_pos,1.0);}


fragment shader:
#version 330uniform sampler2D t_colMap;varying vec2 v_tex;void main() {	gl_FragColor = texture2D(t_colMap,v_tex);}


Also my context creation code is:
void initContext() {	int attribs[] =	{		WGL_CONTEXT_MAJOR_VERSION_ARB, 3,		WGL_CONTEXT_MINOR_VERSION_ARB, 3,		WGL_CONTEXT_FLAGS_ARB,		0	};	rc = wglCreateContextAttribsARB(hdc,0, attribs);}


Another issue I thought about might be is my texture loading (using the devil image lib, glTexImage2D(GL_TEXTURE_2D, ..) and glGenerateMipmap(GL_TEXTURE_2D)), but that works fine with the 3.1 context.

Thanks.
Advertisement
Quote:Original post by andrew111
I'm trying to draw a triangle with a texture mapped to it (using only a shader program, vertex buffers, a uniform buffer, etc so no immediate mode) in the gl context 3.3, but the triangle is rendered black. Though if I use the gl context 3.1, the texture draws fine.


Are you sure your graphics card and/or drivers support 3.3?

NVIDIA press release for the 3.3 drivers lists valid cards:
http://forums.nvidia.com/index.php?showtopic=163444

-me
Ah, I have an ATI Radeon 4800 series card, which I'm sure where to look for compatibility, but that seems most likely reason.
Quote:WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB,
0


This looks wrong, as the flags are supposed to come in pairs, and then terminated with 0. Don't see how it could influence your rendering in that way though, so it's probably unrelated.
Perhaps you want it like this:
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,WGL_CONTEXT_MINOR_VERSION_ARB, 3,WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,0
Quote:Original post by Erik Rufelt
Quote:WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB,
0


This looks wrong, as the flags are supposed to come in pairs, and then terminated with 0. Don't see how it could influence your rendering in that way though, so it's probably unrelated.
Perhaps you want it like this:
*** Source Snippet Removed ***



Yeah you're right, I also had the texture being black problem with the line
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,


but I hadn't removed the whole thing.

thx

This topic is closed to new replies.

Advertisement