Ok, so I’m making fireworks and it works rather well.
As a basis for this I am using sparks, which are rendered as follows:
void Fireworks::render()
{
//set the size of the rendering area
glViewport(0, 0, width, height);
//modelview transform matrix
Matrix4 modelviewmatrix = Matrix4::lookAtMatrix(viewpoint,
viewtarget,
Vector3(0.0f, 0.0f, 1.0f));
//projection transform matrix
Matrix4 projectionmatrix = Matrix4::perspectiveMatrix((float)M_PI_4, (float)width / height, 1.0f, 10000.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//use the terrain shader
glUseProgram(terrainshader.getProgram());
//set our matrices as "uniform" variables
glUniformMatrix4fv(glGetUniformLocation(terrainshader.getProgram(), "matmodelview"), 1, GL_TRUE, modelviewmatrix.elements());
glUniformMatrix4fv(glGetUniformLocation(terrainshader.getProgram(), "matprojection"), 1, GL_TRUE, projectionmatrix.elements());
glBegin(GL_LINES);
spark* p = sparks;
while(p != NULL){
for(int i = 0; i < 3; i++){
glVertex3f(p->position.x(), p->position.y(), p->position.z());
glVertex3f(20.0f*sin(rand())+p->position.x(), 20.0f*cos(rand())+p->position.y(), 20.0f*cos(rand())+p->position.z());
}
p = p->next;
}
glEnd();
These go through the vertex shader which is
out vec3 _color;
void main()
{
// Get a copy of the normal vector
_color = ?
// Transform the vertex position to screencoordinates
gl_Position = matprojection * (matmodelview * in_position);
}
and the fragment shader which is
in vec3 _color; //normal vector
void main()
{
//severely simple lighting model
fragcolor = vec4(_color , 1.0);
}
now I think I got the passing from the vertex to the fragment shader right, but I want to know how I can pass the color information from my program to the vertex shader. I can’t seem to find how to do that…
I could post the rest of the code, but I don’t think it’ll matter (and it’s probably bad anyway). I currently set fragcolor to a fixed color and it works.