problems while using shader

11 views
Skip to first unread message

xing xiaoxiong

unread,
May 4, 2012, 8:22:43 AM5/4/12
to G3D Users
I am trying to render a triangle with GLSL. The shader programs
contain layout qualifiers shown as follows:
//vertex shader
#version 400

layout (location = 0) in vec3 pos;
layout (location = 1) in vec4 color;

smooth out vec4 v2fColor;

void main(void) {
v2fColor = color;
gl_Position = vec4(pos, 1.0);
}


//fragment shader
#version 400

layout (location = 0) out vec4 oColor;

smooth in vec4 v2fColor;

void main() {
oColor = v2fColor;
}

In function onInit(), I set vertex data like:

Point3 p0(-1.0, 0.0, 0.0), p1(1.0, 0.0, 0.0), p2(0.0, 2.0,
0.0);
Color4 c0(1.0, 0.0, 0.0, 1.0), c1(0.0, 1.0, 0.0, 1.0), c2(0.0, 0.0,
1.0, 1.0);

Array<Point3> triVPos(p0, p1, p2);
Array<Color4> triVClr(c0, c1, c2);


vBuf = VertexBuffer::create( (sizeof(Point3) + sizeof(Color4))
* triVPos.size());
vPos = VertexRange(triVPos, vBuf);
vClr = VertexRange(triVClr, vBuf);

triShader = Shader::fromFiles("triShader.vrt", "triShader.pix");

In onGraphics3D(), the function calls are:
rd->beginIndexedPrimitives();

rd->setVertexAttribArray(0, vPos, false);
rd->setVertexAttribArray(1, vClr, true);
rd->setShader(triShader);

rd->sendSequentialIndices(PrimitiveType::TRIANGLES, 3, 0);

rd->endIndexedPrimitives();
But found nothing on the screen. What‘s the problem here?
Reply all
Reply to author
Forward
0 new messages