0
我想在OpenGL和SFML中旋轉一個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();
}
}
here's的教程中,我借鑑。
我不認爲我需要教程代碼頂部的標題,但我是新的,所以我可能是錯的。
使用glTranslatef(0.0f,0.0f,-6.0f);在-Z方向移動三角形SIX UNITS,實際上是在這種情況下,使用默認的視圖和投影矩陣,是在視圖之外的幾個屏幕! –
我想你錯過了至少一個glMatrixMode這裏 –
我以爲glMatrixMode只是在處理3D對象時:/ oops。 – user2727356