我正在尝试在 OpenGL 和 SFML 中旋转 2D 三角形,但由于某种原因,我得到了一个黑屏。如果没有旋转位,代码可以正常工作并显示应有的 2D 三角形,所以我知道这是导致黑屏的旋转代码。
这是我的代码:
#include <SFML/Window.hpp>
int drawTri()
{
GLfloat rtri;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -6.0f);
glRotatef(rtri, 0.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f, 1.0f, 0.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(1.0f, -1.0, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glEnd();
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -6.0f);
rtri+=0.2f;
return 0;
}
int main()
{
sf::WindowSettings winSet;
winSet.DepthBits = 24;
winSet.StencilBits = 8;
winSet.AntialiasingLevel = 2;
sf::Window App(sf::VideoMode(640, 480, 32), "Practice", sf::Style::Close, winSet);
bool isRunning = true;
while(App.IsOpened())
{
sf::Event aEvent;
if(App.GetEvent(aEvent))
if(aEvent.Type == sf::Event::Closed)
isRunning = false;
drawTri();
if(!isRunning)
App.Close();
App.Display();
}
}
这是我正在学习的教程。
我认为我不需要教程代码顶部的标题,但我是新手,所以我可能是错的。