Jump to content
  • Advertisement
Sign in to follow this  
Terrimus

SOLVED: Triangle Strip + GLSL = ?

This topic is 3093 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

I have this test code which works:
          GLShader shader("shaders/test.vert", "shaders/test.frag");
...
		shader.bind();
	
		for(int j = 0; j < 100; j += 10) {
			
			shader.setAttrib1f("a", 1.0f);
			glBegin(GL_TRIANGLE_STRIP);
			
	
			for(int i = 0; i < 100; i += 10) {
				glVertex3f(i, 0, j);
				glVertex3f(i, 0, j + 10);
			}
	
			glEnd();
		}
		
		shader.unbind();
but if I put the setAttrib-call inside the blBegin(), I get some strange results. This:
			glBegin(GL_TRIANGLE_STRIP);
			
	
			for(int i = 0; i < 100; i += 10) {
                                shader.setAttrib1f("a", 1.0f);
				glVertex3f(i, 0, j);
				glVertex3f(i, 0, j + 10);
			}
gives me: I've used shaders + triangle strip before without this issue, and I really don't understand what is wrong. The shaders are really basic:
vert:
attribute float a;

void main() {	
	vec4 v = vec4(gl_Vertex);
	v.y = a;
	
	gl_Position = gl_ModelViewProjectionMatrix * v;
}

frag:
void main() {
	gl_FragColor = vec4(1, 1, 1, 1);
}
The setAttrib-function:
void GLShader::setAttrib1f(const char* name, float value) {
    GLint location = glGetAttribLocationARB(m_prog, name);
    glVertexAttrib1fARB(location, value);
}
[Edited by - Terrimus on December 3, 2009 7:14:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
glGetAttribLocationARB is not supposed to be called between glBegin/glEnd. Try calling it once at initialization of your shader, and store it in a variable for further use, as its value will remain the same. (That is, remember location, instead of getting it every time you use setAttrib1f).

Share this post


Link to post
Share on other sites
I thought attribute variables could be changed at any time?

Anyway, I just found a way around setting the variable per vertex as I thought I had to do.

Edit: I misunderstood your post. Now I see, I can set the attribute variables, but not get the location of the between glBegin-glEnd :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!