1
I am trying to render a circle and a rectangle, and both will have independent motion (Remake of Pong), but the problem is that the glTranslatef() of one is influencing the other, if one goes to the right, the other goes too. Putting to print the values of variables in the console, everything seems to be right.
glColor3f(0.0, 1.0, 0.0);
glRotatef(0.0, 0.0, 0.0, 0.0);
glScalef(1.0, 1.0, 0.0);
glTranslatef(bola.x, bola.y, 0);
CriarBola(0.5, 24);
glRotatef(0.0, 0.0, 0.0, 0.0);
glScalef(1.0, 1.0, 0.0);
glTranslatef(13, player.pos, 0);
CriarQuadrado(player.larg, player.alt);
I believe that the error is not coming from the functions below, but I will put them:
//Função de criar o retangulo
void CriarQuadrado(float larg, float alt)
{
glColor3f(0.0, 0.0, 1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_QUADS);
glVertex3f(-larg, alt, 0.0);
glVertex3f(-larg,-alt, 0.0);
glVertex3f(larg, -alt, 0.0);
glVertex3f(larg, alt, 0.0);
glEnd();
}
//Função de criar o círculo, que é feito a partir de triângulos
void CriarTriangulo(float v1[], float v2[], float v3[])
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_TRIANGLES);
glVertex3fv(v1);
glVertex3fv(v2);
glVertex3fv(v3);
glEnd();
}
void CriarBola(float raio, float faces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
float ang = 2 * PI / faces;
for (short x = 0; x < faces; x++) {
float v1[3]{ raio * std::cos((x + 1) * ang), raio * std::sin((x + 1) * ang), 0 };
float v2[3]{ 0, 0, 0 };
float v3[3]{ raio * std::cos(x * ang), raio * std::sin(x * ang), 0 };
CriarTriangulo(v1, v2, v3);
}
}
you are using a version of Opengl that already makes but decade that was marked as deprecated, look for Modern Opengl
– paulocanedo