Reputation: 144
I have been learning modern OpenGL (3.0) for a couple of weeks now and am trying to create a lunar lander clone in 2D. All tutorials and questions I have read so far did not help at all.
Vertexes in header and other OpenGL:
GLuint vertexArrayLander;
GLuint landerVBO;
GLfloat landerVertex [26] = {
//Lander Body
0.03f, 0.2f,
(-0.03f), 0.2f,
(-0.05f), 0.15f,
(-0.05f), 0.1f,
(-0.03f), 0.05f,
(-0.045f), 0.0f, //left leg
(-0.029f), 0.05f,
(0.029f), 0.05f, //right leg
(0.045f), 0.0f,
0.03f, 0.05f,
0.05f, 0.1f,
0.05f, 0.15f,
0.03f, 0.2f
};
Constructor:
Lander::Lander() {
glGenVertexArrays(1, &vertexArrayLander);
glBindVertexArray(vertexArrayLander);
glGenBuffers(1, &landerVBO);
glBindBuffer(GL_ARRAY_BUFFER, landerVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(landerVertex), landerVertex,GL_STATIC_DRAW);
}
Drawing works so far, but how do I apply x and y to my landerVbo without messing with the array directly? I have tried using glTranslatef(x,y,0.0f) which had no effect at all.
Drawing Method:
void Lander::drawLander() {
float x = position->getX();
float y = position->getY();
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, landerVBO);
glVertexAttribPointer(0, // attribute 0. No particular reason.
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*) 0 // array buffer offset
);
//draw all graphic elements
//How to apply x and y on all points?
glDrawArrays(GL_LINE_STRIP, 0 , 13);
//vao
glDisableVertexAttribArray(0);
}
x and y are the position of the lander on screen. What I want to draw is this pseudo code:
GLfloat landerVertex [26] = {
//Lander Body
x + 0.03f, y + 0.2f,
x + (-0.03f), y + 0.2f,
x + (-0.05f), y + 0.15f,
x + (-0.05f), y + 0.1f,
x + (-0.03f), y + 0.05f,
x + (-0.045f), y + 0.0f, //left leg
x + (-0.029f), y + 0.05f,
x + (0.029f), y + 0.05f, //right leg
x + (0.045f), y + 0.0f,
x + 0.03f, y + 0.05f,
x + 0.05f, y + 0.1f,
x + 0.05f, y + 0.15f,
x + 0.03f, y + 0.2f
};
Upvotes: 0
Views: 719
Reputation: 315
Upvotes: 1