gpt4 book ai didi

c++ - OpenGL glRectf() 不显示

转载 作者:行者123 更新时间:2023-11-30 03:47:52 25 4
gpt4 key购买 nike

glRectf() 没有显示在我的窗口中:

#include <GL/gl.h>
#include <GL/glut.h>

void renderScene(){
glClearColor(0.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glRectf(225.0f,150.0f,150.0f,100.0f);
glFlush();
}

int main(int argc, char*argv[]){
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowSize(450, 350);
glutCreateWindow("My first OpenGL Program...took forever");
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
}

最佳答案

(225.0f,150.0f) 离身份平截头体很远。

提供一些适当的变换矩阵,这样你的矩形就不会被剪裁:

#include <GL/glut.h>

void renderScene()
{
glClearColor(0.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( -300, 300, -300, 300, -1, 1 );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

glColor3f(1.0f,0.0f,0.0f);
glRectf(225.0f,150.0f,150.0f,100.0f);

glFlush();
}

int main(int argc, char*argv[])
{
glutInit( &argc, argv );
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowSize(450, 350);
glutCreateWindow("My first OpenGL Program...took forever");
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
}

关于c++ - OpenGL glRectf() 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33468789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com