Jump to content
  • Advertisement
Sign in to follow this  
smurfkiller

OpenGL opengl 2.0 problems

This topic is 4144 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i have run into some strange problems implementing opengl 2.0 functionality (ATI radeon X1900). The main problem is when i try to bind user defined attributes:
glBindAttribLocation(program, 0, "a_vertex");
glBindAttribLocation(program, 1, "a_normal");
glBindAttribLocation(program, 2, "a_tanu");
glBindAttribLocation(program, 3, "a_tanv");
glBindAttribLocation(program, 4, "a_uvcoord");

int a_vertex = glGetAttribLocation(program, "a_vertex");
int a_norm = glGetAttribLocation(program, "a_normal");
int a_tanu = glGetAttribLocation(program, "a_tanu");
int a_tanv = glGetAttribLocation(program, "a_tanv");
int a_uvcoord = glGetAttribLocation(program, "a_uvcoord");

a_vertex = -1, a_norm = 1, a_tanu = 2, a_tanv = 3, a_uvcoord = -1



No opengl errors generated. When i check attrib location for 'a_vertex' and 'a_uvcoord' the return value is -1. The strange thing is that inside the shader the predefined gl_Vertex attribute is working just fine. How is that possible? The drawing setup code is similar to:
struct Mesh::Vertex {
  vec3 xyz;
  vec3 norm;
  vec3 tanu;
  vec3 tanv;
  vec2 uv;
};

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);

glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glVertexAttribPointer(0, 3, GL_FLOAT, 0, sizeof(Mesh::Vertex), 0);
glVertexAttribPointer(1, 3, GL_FLOAT, 0, sizeof(Mesh::Vertex), (void*)(sizeof(vec3) * 1));
glVertexAttribPointer(2, 3, GL_FLOAT, 0, sizeof(Mesh::Vertex), (void*)(sizeof(vec3) * 2));
glVertexAttribPointer(3, 3, GL_FLOAT, 0, sizeof(Mesh::Vertex), (void*)(sizeof(vec3) * 3));
glVertexAttribPointer(4, 2, GL_FLOAT, 0, sizeof(Mesh::Vertex), (void*)(sizeof(vec3) * 4));	
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
glDrawElements(GL_TRIANGLES, num_triangles * 3, GL_UNSIGNED_INT, 0);
			}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
glBindBuffer(GL_ARRAY_BUFFER,0);

glDisableVertexAttribArray(4);
glDisableVertexAttribArray(3);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(0);



Share this post


Link to post
Share on other sites
Advertisement
Tried that too but the result is the same.
This is my shader create code:

uint create_shader(const char *vs_source, const char *fs_source) {

int status;
uint vs = 0, fs = 0;

if(vs_source) {
vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, &vs_source, 0);
glCompileShader(vs);
glGetShaderiv(vs, GL_COMPILE_STATUS, &status);
if(!status) {
int loglen;
glGetShaderiv(vs, GL_INFO_LOG_LENGTH, &loglen);
if(loglen > 1) {
char *infolog = new char[loglen];
int written;
glGetShaderInfoLog(vs, loglen, &written, infolog);
log_printf("engine: error compiling vertex shader: %s", infolog);
delete infolog;
}
glDeleteShader(vs);
return 0;
}
}

if(fs_source) {
fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, &fs_source, 0);
glCompileShader(fs);
glGetShaderiv(fs, GL_COMPILE_STATUS, &status);
if(!status) {
int loglen;
glGetShaderiv(fs, GL_INFO_LOG_LENGTH, &loglen);
if(loglen > 1) {
char *infolog = new char[loglen];
int written;
glGetShaderInfoLog(fs, loglen, &written, infolog);
log_printf("engine: error compiling fragment shader: %s", infolog);
delete infolog;
}
glDeleteShader(vs);
glDeleteShader(fs);
return 0;
}
}

uint program = glCreateProgram();

if(vs) {
glAttachShader(program, vs);
glDeleteShader(vs);
}
if(fs) {
glAttachShader(program, fs);
glDeleteShader(fs);
}

glBindAttribLocation(program, 0, "a_vertex");
glBindAttribLocation(program, 1, "a_normal");
glBindAttribLocation(program, 2, "a_tanu");
glBindAttribLocation(program, 3, "a_tanv");
glBindAttribLocation(program, 4, "a_uvcoord");

glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &status);
if(!status) {
int loglen;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &loglen);
if(loglen > 1) {
char *infolog = new char[loglen];
int written;
glGetProgramInfoLog(program, loglen, &written, infolog);
log_printf("engine: error linking shader program: %s", infolog);
delete infolog;
}
glDeleteProgram(program);
return 0;
}



return program;
}

Share this post


Link to post
Share on other sites

I think, the attribute 'a_vertex' is not getting used in your shader. Binding is done only for used varibales

Check your shader again .

Share this post


Link to post
Share on other sites
I don't think its that ether, my shader looks something like this:

[vs]

attribute vec3 a_vertex;
attribute vec3 a_normal;
attribute vec3 a_tanu;
attribute vec3 a_tanv;
attribute vec2 a_uvcoord;

uniform vec4 u_light;
uniform vec4 u_camera;

varying vec3 v_lvec;
varying vec3 v_vvec;
varying vec3 v_norm;

void main() {
gl_Position = ftransform(); // gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0);

vec3 lvec = u_light.xyz - gl_Vertex.xyz;
//v_lvec.x = dot(lvec, a_tanu);
//v_lvec.y = dot(lvec, a_tanv);
//v_lvec.z = dot(lvec, a_normal);
v_lvec = lvec;

vec3 vvec = u_camera.xyz - gl_Vertex.xyz;
//v_vvec.x = dot(vvec, a_tanu);
//v_vvec.y = dot(vvec, a_tanv);
//v_vvec.z = dot(vvec, a_normal);
v_vvec = vvec;

v_norm = a_normal;
}

I checked some other sources and almost none of them even use glBindAttribLocation for the attributes. The strange thing is that it works if i use ARB glsl extensions instead of opengl 2.0.

Share this post


Link to post
Share on other sites
Okay. But again, I think, its the same problem.

Quote:

gl_Position = ftransform(); // gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0);


a_vertex is commented. Its not getting used in your shader. So as a_uvcoord

That should be the problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!