使用OpenGL的多边形投影

问题描述 投票:0回答:1

我正在尝试使用open-GL实现透视投影但是当我应用gluPerspective(0,0.5,0.5,5)方法时,多边形未在透视图中显示,而在正交视图中显示这是输出enter image description here任何人都可以帮助我的代码:

#include<GL/glut.h>
float angle = 2;
void myinit(void)
{
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    //glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 5);
    //glFrustum(-0.5, 2.4, -0.5, 0.5, -0.5, 0.5);
    //glFrustum(-5.0, 5.0, -5.0, 5.0, 5, 100);
    gluPerspective(0,0.5,0.5,5);
}

void polygon(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0, 0.0, 1.0);
    //glLineWidth(2);
    //glRotatef(angle, 0.0, 0.0, 1.0);
    glBegin(GL_POLYGON);
    glVertex3f(0.25, 0.25, 0.0);
    glVertex3f(0.75, 0.25, 0.0);
    glVertex3f(0.75, 0.75, 0.0);
    glVertex3f(0.25, 0.75, 0.0);
    //glVertex3f(0, 0.5, 0.0);
    glEnd();
    glFlush();
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(50, 100);
    glutInitWindowSize(1000, 1000);
    glutCreateWindow("Open Gl 2D Geometric Transformation");
    myinit();
    glutDisplayFunc(polygon);
    glutMainLoop();


    return 0;
}
c++ opengl projection
1个回答
0
投票

gluPerspective的第一个参数是错误的:

© www.soinside.com 2019 - 2024. All rights reserved.