I am able to store my vertices in an array(_hillVertices = CGPointMake(x, y);) and draw it as a line using ccDrawLine (not with the opengl method you supplied) in my draw method.
I'm not able to use a texture below my b2ChainShape.
What I wanna do:
1. loop through my vertices and save their coordinates (done)
2. use glVertexAttribPointer to show my line being drawn (so that I won't have to use ccDrawLine).
3. render with a texture using open gl es 2(should be ready when step 2 is done?)
the tutorial at wenderlichs site is great for dynamically creating curves but I can't get the same effect using my RUBE vertices. I've tried all day, but you know what it's like when you get stuck on a problem, you can't think straight - at least I can't
any help is greatly appreciated. thanks.
EDIT: what's confusing me most right now is
_hillVertices <- the vertex coordinates?
_hillTexCoords <- ? same coordinates converted to opengl points?
_nHillVertices <- the convertex vertex points?
The code from Wenderlich that messes it up is this:
I'm trying to rewrite this to make it work with RUBE. I'm aware that it's somewhat off-topic. But since you asked the same question and seem to have solved the problem - any help from you would be great.
b2ChainShape* chainShape = (b2ChainShape*)fixture->GetShape();
int numEdges = chainShape->GetChildCount();
int numVertices = chainShape->m_hasNextVertex ? numEdges : numEdges + 1;
b2EdgeShape edgeShape;
for (int i = 0; i < numEdges; i++) {
chainShape->GetChildEdge( &edgeShape, i );
b2Vec2 vertex = edgeShape.m_vertex1;
// ... do something with the vertex ...
}
the code you posted, are you using it in your -(void)afterLoadProcessing:(b2dJson*)json method?
to me it seems like there's a lot of obsolete code - I could be wrong of course.
vkreal, can you post a sample of a stripped down project showing your code in action? thanks again
I'm wondering if you have actually made vertices for a triangle strip, instead of just the line that you get from RUBE. You mention that you can draw the line segments from RUBE with ccDrawLine, but did you then create another lower line of vertices necessary to make triangles from that? Putting textures aside for a moment, can you draw the triangles you need with just plain color?
The simplest method of creating a triangle strip from the RUBE line would have one vertex underneath every vertex in the RUBE line, and these would need to be at every second position in the vertex array. The overall vertex array used to draw should have twice as many vertices as were loaded from the RUBE line. Have you done anything like that?
Note that this technique only works if the vertices in the original line are consistently going from left to right (or vice versa), otherwise the resulting shape will be concave and you will need more complex methods of generating triangles for it.
sorry can't give out code belong to others, but i can point you in right direction. Code up above works, it's use to fill RUBE terrain vertices and texCoords for draw method, this code should be inside your update method. _hillKeyPoints should be filled with your rube terrain points. Like stated before its almost exactly like Ray's tut instead use terrain vertices.
iforce2d wrote:I'm wondering if you have actually made vertices for a triangle strip, instead of just the line that you get from RUBE. You mention that you can draw the line segments from RUBE with ccDrawLine, but did you then create another lower line of vertices necessary to make triangles from that? Putting textures aside for a moment, can you draw the triangles you need with just plain color?
The simplest method of creating a triangle strip from the RUBE line would have one vertex underneath every vertex in the RUBE line, and these would need to be at every second position in the vertex array. The overall vertex array used to draw should have twice as many vertices as were loaded from the RUBE line. Have you done anything like that?
Note that this technique only works if the vertices in the original line are consistently going from left to right (or vice versa), otherwise the resulting shape will be concave and you will need more complex methods of generating triangles for it.
thanks buddy, this pointed me in the right direction - problem solved!