PDA

View Full Version : gldrawelements crash



adamnation
06-12-2005, 08:10 AM
When I call gldrawelements my program crashes.

When I comment out my shader code it works fine. The code is as follows:


vshader = glCreateShader(GL_VERTEX_SHADER);
fshader = glCreateShader(GL_FRAGMENT_SHADER);

glShaderSource(vshader, length,source, NULL);
glShaderSource(fshader, length,source2, NULL);

glCompileShader(vshader);
glCompileShader(fshader);

shaderprog = glCreateProgram();
glAttachShader(shaderprog,vshader);
glAttachShader(shaderprog,fshader);
glLinkProgram(shaderprog);

loc = glGetAttribLocation(shaderprog, "Tangent");
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,0,ta ngents);Running a Radeon 9600 Pro, latest catalyst drivers. Anybody know what I'm doing wrong?

execom_rt
06-12-2005, 01:43 PM
Originally posted by adamnation:
loc = glGetAttribLocation(shaderprog, "Tangent");
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,0,ta ngents);it's non sense. Write instead :

glBindAttribLocationARB(program, 6, "Tangent"); // Use attrib 6 (reserved for tangents - see glTangentPointerEXT).
glLinkProgramARB(program); // Need to link a second time.
glVertexAttribPointer(6,3,GL_FLOAT,GL_FALSE,0,tang ents);

adamnation
06-13-2005, 04:17 AM
What about what I wrote is non-sense? Exactly how is that not the proper way to send vertex attributes to a shader?

What benefit is derived from using location six for tangents? Its just a vec3 in the shader anyways. Why is glBind AttribLocations being used instead of what I have?

Confused,
AdamNation :confused:

Ffelagund
06-13-2005, 06:07 AM
Dont worry. You can ask for the attribute location AFTER the program was linked, instead of assign manually the slot.

A crash at a glDrawxxxx call, is caused usually by a bad initialization of the used arrays. You probably forgot to disable any array that was previoulsly enabled but is not used, or some of the used arrays are smaller than they should be (perhaps because you are setting up a vec3 vector and passing an array of vec2 vectors), or you are using an invalid pointer... There are a lot of possibilites.

execom_rt
06-13-2005, 07:00 AM
Yes, it might something else than the vertex attrib binding.

Try a very simple shader, see what's happening, or use GLIntercept, this will help to track down othe issues.

adamnation
06-20-2005, 07:03 PM
Okay, I'm using glBindAttribLocation as well as gldrawarrays now, I've also made sure that all the data was where it was supposed to be, so there's no missing values, or too-short arrays or anything like that.

Still its crashing. Now when I comment all the shader code out, it runs fine.

One interesting note, after:

glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,0,ta ngents);I have:

void* foo = NULL;
glGetVertexAttribPointerv(loc[9],GL_VERTEX_ATTRIB_ARRAY_POINTER,&foo);The value returned to foo is NULL, so looks like there's trouble with glVertexAttribPointer.

Thanks!
AdamNation