Jump to content

  • Log In with Google      Sign In   
  • Create Account


[GLSL] Changing Vertex Attributes After glBegin(GL_TRIANGLES) ...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 newObjekt   Members   -  Reputation: 204

Like
0Likes
Like

Posted 20 March 2013 - 05:30 PM

Okay so I have a weird problem. I'm using Java, LWJGL, and GLSL.

 

Basically heres the problem.

 

This code gets me this result - http://inferno.codebrainshideout.net/Images/glslbug2.png

public class Triangle {

	//Triangle coordinates
	public Vertex a, b, c;
	//Triangle normals
	public Vertex i, j, k;
	//Triangle texture coordiantes
	public Vertex u, v, w;
	//Triangle Material
	public Material mat;
	//Model that this triangle belongs too.
	public Model model;

//// constructor and other methods here /////

public void draw() {
		mat.glMaterialSet();		

		glVertexAttrib3f(glGetAttribLocation(GraphicsCore.program, "indices"), (float)a.weights[0].frame.index, 0, 0);

		glBegin(GL_TRIANGLES);

		glTexCoord3d(u.x, u.y, u.z);
		glNormal3d(i.x, i.y, i.z);
		glVertex3d(a.x, a.y, a.z);
		
		glTexCoord3d(v.x, v.y, v.z);
		glNormal3d(j.x, j.y, j.z);
		glVertex3d(b.x, b.y, b.z);

		glTexCoord3d(w.x, w.y, w.z);
		glNormal3d(k.x, k.y, k.z);
		glVertex3d(c.x, c.y, c.z);
		
		glEnd();
}
}


But if I move glVertexAttrib3f() inside of the glBegin() I get this - http://inferno.codebrainshideout.net/Images/glslbug1.png

public class Triangle {

	//Triangle coordinates
	public Vertex a, b, c;
	//Triangle normals
	public Vertex i, j, k;
	//Triangle texture coordiantes
	public Vertex u, v, w;
	//Triangle Material
	public Material mat;
	//Model that this triangle belongs too.
	public Model model;

//// constructor and other methods here /////

public void draw() {
		mat.glMaterialSet();		

		glBegin(GL_TRIANGLES);

		glVertexAttrib3f(glGetAttribLocation(GraphicsCore.program, "indices"), (float)a.weights[0].frame.index, 0, 0);

		glTexCoord3d(u.x, u.y, u.z);
		glNormal3d(i.x, i.y, i.z);
		glVertex3d(a.x, a.y, a.z);
		
		glTexCoord3d(v.x, v.y, v.z);
		glNormal3d(j.x, j.y, j.z);
		glVertex3d(b.x, b.y, b.z);

		glTexCoord3d(w.x, w.y, w.z);
		glNormal3d(k.x, k.y, k.z);
		glVertex3d(c.x, c.y, c.z);
		
		glEnd();
}
}

 

What did I do wrong? I've seen people change attributes during there glBegin in examples. Why does it literally destroy my model when I do it?

 

This happens with any attribute I try to change, regardless of the data in it. Basically if I use glVertexAttrib() in any way inside of glBegin I get this problem.

 

I need to change the indices attribute for each vertex in the triangle, but I can't do that because any attributes I change inside of glBegin causes that to happen. What do?



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7436

Like
0Likes
Like

Posted 20 March 2013 - 06:42 PM

Very probably because "glGetAttribLocation(GraphicsCore.program, "indices")" returned 0, which is specified to be equivalent to a glVertex call.  You should explicitly set this (before program link time) using glBindAttribLocation so that you've a valid (non-zero) value in it, and so that you don't have to be calling glGetAttribLocation constantly at runtime (which may be slow).

 

Even if it didn't, you shouldn't mix glVertexAttrib calls with fixed attrib calls (glVertex/glTexcoord/etc) - use either one or the other.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 newObjekt   Members   -  Reputation: 204

Like
0Likes
Like

Posted 20 March 2013 - 09:27 PM

Yeah I talked with my friend who had more experiance. I stopped using glBegin and started using interleaved VertexBuffers. All is well now.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS