Sign in to follow this  
andrew111

Textures come up black when using a gl 3.3 context

Recommended Posts

andrew111    310
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 330
layout(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 330
uniform 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.

Share this post


Link to post
Share on other sites
Palidine    1315
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

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
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

Share this post


Link to post
Share on other sites
andrew111    310
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this