Seraphis
November 23rd, 2006, 09:47 PM
O.K. So I've been learning OpenGL and I was messing around with drawing shapes when I got the idea of making a triangle, which could via the W,A,S,D keys have its vertices moved about the screen to reshape it.
I got it working with 1 vertex, just by making a GLfloat , and manipulating it with
if (keys['S']) { blah blah }
The idea I came up with to make a multidimensional array which used a variable in the brackets to change the vertex every time the user hits enter.... Heres what I got.
**My Variables**
GLfloat p1[10];
GLfloat p2[10];
GLfloat p3[10];
int stc=0;
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0,0);
glRotatef(rtri,0.0f,1.0f,0.0f);
glRotatef(rtriz,1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(p1[0],p2[0],p3[0]);
glVertex3f(p1[1],p2[1],p3[1]);
glVertex3f(p1[2],p2[2],p3[2]);
glEnd();
if (keys['W'])
{
keys['W'] = FALSE;
p1[stc]+=0.1f;
}
if (keys['S'])
{
keys['S'] = FALSE;
p1[stc]-=0.1f;
}
if (keys[VK_RETURN])
{
if (stc < 3)
{
stc++;
}
else if (stc > 2)
{
stc = 0;
}
}
return TRUE; //
}
In theory, this should make it so you can cycle through the 3 vertices and moved the X position, positive or negative.
I get no errors when I compile it, but when I run it theres no triangle... which makes sense considering all of the points on it are 0.0f . But when I push 'W' to bring the 1st vertex up, nothing happens.
Thoughts?
Thx in advance,
Seraphis
I got it working with 1 vertex, just by making a GLfloat , and manipulating it with
if (keys['S']) { blah blah }
The idea I came up with to make a multidimensional array which used a variable in the brackets to change the vertex every time the user hits enter.... Heres what I got.
**My Variables**
GLfloat p1[10];
GLfloat p2[10];
GLfloat p3[10];
int stc=0;
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0,0);
glRotatef(rtri,0.0f,1.0f,0.0f);
glRotatef(rtriz,1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(p1[0],p2[0],p3[0]);
glVertex3f(p1[1],p2[1],p3[1]);
glVertex3f(p1[2],p2[2],p3[2]);
glEnd();
if (keys['W'])
{
keys['W'] = FALSE;
p1[stc]+=0.1f;
}
if (keys['S'])
{
keys['S'] = FALSE;
p1[stc]-=0.1f;
}
if (keys[VK_RETURN])
{
if (stc < 3)
{
stc++;
}
else if (stc > 2)
{
stc = 0;
}
}
return TRUE; //
}
In theory, this should make it so you can cycle through the 3 vertices and moved the X position, positive or negative.
I get no errors when I compile it, but when I run it theres no triangle... which makes sense considering all of the points on it are 0.0f . But when I push 'W' to bring the 1st vertex up, nothing happens.
Thoughts?
Thx in advance,
Seraphis