使用具有每条边的x,y坐标的数组,我可以绘制2D多边形。 之后,我想在3D中挤出它。 我想到了一种方法,通过为我的顶点数组添加深度来实现这一点,首先我使用线条绘制并在x,y,0处绘制我的形状底部glvertex3,然后我用x,y,0.8重绘( 0.8是增加的深度)最后我用一条线连接边缘,每条边从x,y,0到x,y,0.8
glPushMatrix();
glColor3f(color_outline.red, color_outline.green, color_outline.blue);
int i = 0;
glBegin(GL_LINE_STRIP);
for (i = 0; i < coord_iterator; i++)
{
glVertex3f((float)mouse_x_coord[i], (float)mouse_y_coord[i],0);
newx[i] = (float)mouse_x_coord[coord_iterator];
newy[i] = (float)mouse_y_coord[coord_iterator];
}
newx[coord_iterator] = (float)mouse_x_coord[coord_iterator];
newy[coord_iterator] = (float)mouse_y_coord[coord_iterator];
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f((float)mouse_x_coord[i - 1], (float)mouse_y_coord[i - 1],0);
glVertex3f((float)mouse_x_coord[i], (float)mouse_y_coord[i],0);
glVertex3f((float)mouse_x_coord[0], (float)mouse_y_coord[0],0);
glEnd();
glPopMatrix();
glBegin(GL_LINE_STRIP);
for (i = 0; i<coord_iterator; i++)
{
glVertex3f(newx[i], newy[i],0.8);
}
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(newx[i-1], newy[i-1],0.8);
glVertex3f(newx[i], newy[i],0.8);
glVertex3f(newx[0], newy[0],0.8);
printf("newx %d newy %d", newx[i], newy[i]);
glEnd();
glPopMatrix();
for (i = 0; i<=coord_iterator; i++)
{
glBegin(GL_LINE);
glVertex3f(newx[i], newy[i],0.8);
glVertex3f((float)mouse_x_coord[i],(float)mouse_y_coord[i],0.8);
glEnd();
}
glutSwapBuffers(); //swap the buffers
我现在的问题是我无法在3d中看到它,我已经初始化了我的窗口 与
gluOrtho2D(0.0f, (float)window_width, 0.0f, (float)window_height);
但是gluOrtho2D实际上是打电话
void gluOrtho2D(
GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top )
{
glOrtho(left, right, bottom, top, -1, 1);
}
这意味着我有一个-1到1深度的3D系统,但我能看到的是我之前绘制的多边形