PDA

View Full Version : Help with Triangle strip



Jeffg
12-29-2010, 07:20 PM
I'm trying to understand this code below and it has me confused (Attempting to convert Volumetric lines (http://sebastien.hillaire.free.fr/demos/simplevolumeline/vline.htm) to Java). 6 triangles are used for each line (8 vertex).

What I don't get is that the first 4 vertexs are p1 and the second 4 vertexs are p2. How is this working? When I try to duplicate this, I don't get anything even when I remove everything but the vertexs and attempt to just draw the triangles.

Here is the loop.

glColor3f(1.0,1.0,1.0);
for(int vl=0;vl<nbVLine;vl++)
{

VolumeLineRenderer::getInstance().renderLine(vline[vl*2],vline[vl*2+1]);
}

void VolumeLineRenderer::renderLine(float *p1, float *p2)
{

glBegin(GL_TRIANGLE_STRIP);
glNormal3fv(vline_vertexOffset[0]);
glTexCoord2fv(vline_texCoord[0]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p2[0], p2[1], p2[2], 1.0f);
glVertex3fv(p1);
glNormal3fv(vline_vertexOffset[1]);
glTexCoord2fv(vline_texCoord[1]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p2[0], p2[1], p2[2], 1.0f);
glVertex3fv(p1);
glNormal3fv(vline_vertexOffset[2]);
glTexCoord2fv(vline_texCoord[2]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p2[0], p2[1], p2[2], 1.0f);
glVertex3fv(p1);
glNormal3fv(vline_vertexOffset[3]);
glTexCoord2fv(vline_texCoord[3]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p2[0], p2[1], p2[2], 1.0f);
glVertex3fv(p1);

glNormal3fv(vline_vertexOffset[4]);
glTexCoord2fv(vline_texCoord[4]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p1[0], p1[1], p1[2], 1.0f);
glVertex3fv(p2);
glNormal3fv(vline_vertexOffset[5]);
glTexCoord2fv(vline_texCoord[5]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p1[0], p1[1], p1[2], 1.0f);
glVertex3fv(p2);
glNormal3fv(vline_vertexOffset[6]);
glTexCoord2fv(vline_texCoord[6]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p1[0], p1[1], p1[2], 1.0f);
glVertex3fv(p2);
glNormal3fv(vline_vertexOffset[7]);
glTexCoord2fv(vline_texCoord[7]);
glVertexAttrib4f(this->gpuProgVolumeLine_other, p1[0], p1[1], p1[2], 1.0f);
glVertex3fv(p2);
glEnd();
}

float vline[][3] =
{
{0.0f, 0.0f, 0.0f}, {10.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f}, {0.0f, 10.0f, 0.0f},
{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 10.0f},
{15.0f, 0.0f, 0.0f}, {25.0f, 0.0f, 0.0f},
{15.0f, 0.0f, 0.0f}, {15.0f, 10.0f, 0.0f},
{15.0f, 0.0f, 0.0f}, {15.0f, 0.0f, 10.0f},
{10.0f, 0.0f, 20.0f}, {20.0f, 5.0f, 25.0f},
{20.0f, 5.0f, 25.0f}, {30.0f, -1.0f, 22.0f},
{30.0f, -1.0f, 22.0f}, {35.0f, 2.0f, 20.0f},
{-6.0f, 10.0f, 3.0f}, {-5.0f, 0.0f, 2.0f},
{-6.0f, 0.0f, 2.0f}, {-3.0f, 15.0f, -2.0f},
{-2.0f, 11.0f, -1.0f}, {-6.0f, 3.0f, 0.5f}
};

Jeffg
12-30-2010, 09:13 AM
Do I need to provide more information? I'm really stuck on this. How does this create 6 triangles out of two points?

Here is the vert shader, VertexAttrib above applies to "other".

attribute vec4 other;
uniform float lineWidth;
varying vec4 color;
void main() {

gl_TexCoord[0] = gl_MultiTexCoord0;

color = gl_Color;

vec4 vMVP = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 otherMVP = gl_ModelViewProjectionMatrix * other;


vec2 lineDirProj = lineWidth * normalize( (vMVP.xy/vMVP.w) - (otherMVP.xy/otherMVP.w) );


if( sign(otherMVP.w) != sign(vMVP.w) ) {
lineDirProj = -lineDirProj;
}


vMVP.x = vMVP.x + lineDirProj.x * gl_Normal.x;
vMVP.y = vMVP.y + lineDirProj.y * gl_Normal.x;

vMVP.x = vMVP.x + lineDirProj.y * gl_Normal.y;
vMVP.y = vMVP.y - lineDirProj.x * gl_Normal.y;

gl_Position = vMVP;

}

Jeffg
12-30-2010, 09:52 AM
Disregard... I still don't know how it works, but I have it working now. So I can accept the magic and move on.