Very recently I posted a question on transformations this is pretty much the same but I think I might be quite close to success after hunting around on the net although something must be going wrong because the rendered object disappears when I run the program. Here is the draw function:
- Code: Select all
void Draw(void)
{
GLint loc;
GLfloat viewMatrix[16] = {
1.0,0.0,0.0,0.0,
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
0.0,0.0,0.0,1.0};
static GLfloat trans[4] = {
0.0,0.0,0.0,0.0
};
static GLfloat rot[4] = {
0.0, 0.0, 0.0, 0.0
};
static GLfloat shotTrans[4] = {
0.0,0.0,0.0,0.0
};
static GLfloat move = 0.01;
static int first = 1;
float angle = 90.0f;
glViewport(0, 0, state->render_width, state->render_height);
glClear( GL_COLOR_BUFFER_BIT );
float c = cos(90*3.14159f/180.0f);
float s = sin(90*3.14159f/180.0f);
rot[0] = c;
rot[1] = s;
rot[2] = -s;
rot[3] = c;
fprintf(stderr, "%f %f\n", s, c);
if (upPressed == 1)
{
if (trans[1] > 1.0 - 0.3)
trans[1] = trans[1];
else
trans[1] += 0.01;
}
if (rightPressed == 1)
{
if (trans[0] > 1.0 - 0.06)
trans[0] = trans[0];
else
trans[0] += 0.01;
}
if (leftPressed == 1)
{
if (trans[0] < -1.0 + 0.06)
trans[0] = trans[0];
else
trans[0] -= 0.01;
}
if (downPressed == 1)
{
if (trans[1] < -1.0 - 0.16)
trans[1] = trans[1];
else
trans[1] -= 0.01;
}
//trans[0] += move;
//if( (trans[0] > 1.0) || (trans[0] < -1.0)) move *= -1.0;
shader_select(shader);
glLineWidth(3.0f);
if(first)
{
first = 0;
loc = glGetUniformLocation( shader->program, "u_mvpMatrix" );
printf("locmvp=%d\n",loc);
loc = glGetUniformLocation( shader->program, "u_Translate" );
printf("loctrans=%d\n",loc);
loc = glGetUniformLocation( shader->program, "u_Rotate" );
printf("locrot=%d\n", loc);
loc = glGetAttribLocation( shader->program, "a_position" );
printf("locposn=%d\n",loc);
}
glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 0, ship );
glEnableVertexAttribArray( 0 );
glUniformMatrix4fv(2 , 1, GL_FALSE, (GLfloat*) &viewMatrix[0] );
glUniform4fv(1 , 1, (GLfloat *) &trans[0]);
glUniform4fv(0, 1, (GLfloat *) &rot[0]);
glDrawArrays ( GL_LINES, 0, 4 );
}
And the shader code....
- Code: Select all
GLchar vShaderStr[] =
"uniform mat4 u_mvpMatrix; \n"
"uniform vec4 u_Translate; \n"
"uniform mat2 u_Rotate; \n"
"attribute vec4 a_position; \n"
"void main() \n"
"{ \n"
" vec4 posn; \n"
" posn = a_position + u_Translate; \n"
" posn.xy = a_position.xy * u_Rotate; \n"
" gl_Position = u_mvpMatrix * posn; \n"
"} \n";
I have also attached the full source along with this message if you need anything else. Any help is appreciated.