C++ 闪烁(后缓冲?)
运行应用程序后,应用程序的视口将以闪烁模式在两个渲染之间闪烁。我想前后缓冲区正在交换 我怎样才能防止这种情况?我希望所有的三角形都能一直显示在屏幕上 我正在做一个锡宾斯基垫圈(我很接近,但还没有完成。别告诉我我想弄清楚!)。不过,我对一般代码清理感兴趣。我愿意接受任何建议C++ 闪烁(后缓冲?),c++,opengl,C++,Opengl,运行应用程序后,应用程序的视口将以闪烁模式在两个渲染之间闪烁。我想前后缓冲区正在交换 我怎样才能防止这种情况?我希望所有的三角形都能一直显示在屏幕上 我正在做一个锡宾斯基垫圈(我很接近,但还没有完成。别告诉我我想弄清楚!)。不过,我对一般代码清理感兴趣。我愿意接受任何建议 #include SFML/Graphics.hpp #include GL/glew.h using namespace sf; struct point { float x, y; // z is always
#include SFML/Graphics.hpp
#include GL/glew.h
using namespace sf;
struct point
{
float x, y; // z is always 0 ... for now. MWUAHAHAA
};
point points[3] = {{0.f, 1.f}, // top
{-1.f, -1.f}, // left
{ 1.f, -1.f}}; // right
point temp = {points[0].x, points[0].y};
void renderFirstTriangle()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[0].x, points[0].y, 0.f);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[1].x, points[1].y, 0.f);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[2].x, points[2].y, 0.f);
glEnd();
}
int main()
{
Window window(VideoMode(800, 600), "Fractal", Style::Default, ContextSettings(32));
window.setVerticalSyncEnabled(true);
renderFirstTriangle();
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
else if (event.type == Event::Closed)
window.close();
}
for (int i = 0; i < 2; i++)
{
// calculate new vertex positions
temp.x = points[0].x;
temp.y = points[0].y;
glBegin(GL_TRIANGLES);
if( i % 2 )
glColor3f(0.1f, 0.1f, 0.1f);
glVertex3f((points[0].x + points[1].x) / 2, (points[0].y + points[1].y) / 2, 0.0f);
glVertex3f((points[1].x + points[2].x) / 2, (points[1].y + points[2].y) / 2, 0.0f);
glVertex3f((points[2].x + temp.x) / 2, (points[2].y + temp.y) / 2, 0.0f);
glEnd();
}
window.display();
}
}
#包括SFML/Graphics.hpp
#包括总帐/总帐
使用名称空间sf;
结构点
{
浮点x,y;//z始终为0…现在。MWUAHAHAA
};
点点[3]={{0.f,1.f},//顶部
{-1.f,-1.f},//左
{1.f,-1.f}};//正确的
点温度={点[0].x,点[0].y};
void renderFirstTriangle()
{
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
glBegin(GL_三角形);
GL3F(1.f,1.f,1.f);
glVertex3f(点[0].x,点[0].y,0.f);
GL3F(1.f,1.f,1.f);
glVertex3f(点[1].x,点[1].y,0.f);
GL3F(1.f,1.f,1.f);
glVertex3f(点[2].x,点[2].y,0.f);
格伦德();
}
int main()
{
窗口窗口(视频模式(800600),“分形”,样式::默认,上下文设置(32));
window.setVerticalSyncEnabled(真);
renderFirstTriangle();
while(window.isOpen())
{
事件;
while(window.pollEvent(事件))
{
if(event.type==event::Resized)
glViewport(0,0,event.size.width,event.size.height);
else if(event.type==event::Closed)
window.close();
}
对于(int i=0;i<2;i++)
{
//计算新的顶点位置
温度x=点[0].x;
温度y=点[0].y;
glBegin(GL_三角形);
如果(i%2)
GL3F(0.1f、0.1f、0.1f);
glVertex3f((点[0].x+点[1].x)/2,(点[0].y+点[1].y)/2,0.0f);
glVertex3f((点[1].x+点[2].x)/2,(点[1].y+点[2].y)/2,0.0f);
glVertex3f((点[2].x+temp.x)/2,(点[2].y+temp.y)/2,0.0f);
格伦德();
}
window.display();
}
}
每次通过主循环清除屏幕:
// g++ main.cpp -lGL -lsfml-graphics -lsfml-window
// using SFML 1.6
#include <SFML/Graphics.hpp>
using namespace sf;
struct point
{
float x, y; // z is always 0 ... for now. MWUAHAHAA
};
point points[3] = {{0.f, 1.f}, // top
{-1.f, -1.f}, // left
{ 1.f, -1.f}}; // right
point temp = {points[0].x, points[0].y};
void renderFirstTriangle()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[0].x, points[0].y, 0.f);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[1].x, points[1].y, 0.f);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[2].x, points[2].y, 0.f);
glEnd();
}
int main()
{
Window window(VideoMode(800, 600), "Fractal");
window.UseVerticalSync(true);
renderFirstTriangle();
while (window.IsOpened())
{
Event event;
while (window.GetEvent(event))
{
if (event.Type == Event::Resized)
glViewport(0, 0, event.Size.Width, event.Size.Height);
else if (event.Type == Event::Closed)
window.Close();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (int i = 0; i < 2; i++)
{
// calculate new vertex positions
temp.x = points[0].x;
temp.y = points[0].y;
glBegin(GL_TRIANGLES);
if( i % 2 )
glColor3f(0.1f, 0.1f, 0.1f);
glVertex3f((points[0].x + points[1].x) / 2, (points[0].y + points[1].y) / 2, 0.0f);
glVertex3f((points[1].x + points[2].x) / 2, (points[1].y + points[2].y) / 2, 0.0f);
glVertex3f((points[2].x + temp.x) / 2, (points[2].y + temp.y) / 2, 0.0f);
glEnd();
}
window.Display();
}
}
//g++main.cpp-lGL-lsfml图形-lsfml窗口
//使用SFML1.6
#包括
使用名称空间sf;
结构点
{
浮点x,y;//z始终为0…现在。MWUAHAHAA
};
点点[3]={{0.f,1.f},//顶部
{-1.f,-1.f},//左
{1.f,-1.f}};//正确的
点温度={点[0].x,点[0].y};
void renderFirstTriangle()
{
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
glBegin(GL_三角形);
GL3F(1.f,1.f,1.f);
glVertex3f(点[0].x,点[0].y,0.f);
GL3F(1.f,1.f,1.f);
glVertex3f(点[1].x,点[1].y,0.f);
GL3F(1.f,1.f,1.f);
glVertex3f(点[2].x,点[2].y,0.f);
格伦德();
}
int main()
{
窗口(视频模式(800600),“分形”);
window.UseVerticalSync(true);
renderFirstTriangle();
while(window.IsOpened())
{
事件;
while(window.GetEvent(event))
{
if(event.Type==event::Resized)
glViewport(0,0,event.Size.Width,event.Size.Height);
else if(event.Type==event::Closed)
window.Close();
}
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
对于(int i=0;i<2;i++)
{
//计算新的顶点位置
温度x=点[0].x;
温度y=点[0].y;
glBegin(GL_三角形);
如果(i%2)
GL3F(0.1f、0.1f、0.1f);
glVertex3f((点[0].x+点[1].x)/2,(点[0].y+点[1].y)/2,0.0f);
glVertex3f((点[1].x+点[2].x)/2,(点[1].y+点[2].y)/2,0.0f);
glVertex3f((点[2].x+temp.x)/2,(点[2].y+temp.y)/2,0.0f);
格伦德();
}
window.Display();
}
}
每次通过主循环清除屏幕:
// g++ main.cpp -lGL -lsfml-graphics -lsfml-window
// using SFML 1.6
#include <SFML/Graphics.hpp>
using namespace sf;
struct point
{
float x, y; // z is always 0 ... for now. MWUAHAHAA
};
point points[3] = {{0.f, 1.f}, // top
{-1.f, -1.f}, // left
{ 1.f, -1.f}}; // right
point temp = {points[0].x, points[0].y};
void renderFirstTriangle()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[0].x, points[0].y, 0.f);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[1].x, points[1].y, 0.f);
glColor3f(1.f, 1.f, 1.f);
glVertex3f(points[2].x, points[2].y, 0.f);
glEnd();
}
int main()
{
Window window(VideoMode(800, 600), "Fractal");
window.UseVerticalSync(true);
renderFirstTriangle();
while (window.IsOpened())
{
Event event;
while (window.GetEvent(event))
{
if (event.Type == Event::Resized)
glViewport(0, 0, event.Size.Width, event.Size.Height);
else if (event.Type == Event::Closed)
window.Close();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (int i = 0; i < 2; i++)
{
// calculate new vertex positions
temp.x = points[0].x;
temp.y = points[0].y;
glBegin(GL_TRIANGLES);
if( i % 2 )
glColor3f(0.1f, 0.1f, 0.1f);
glVertex3f((points[0].x + points[1].x) / 2, (points[0].y + points[1].y) / 2, 0.0f);
glVertex3f((points[1].x + points[2].x) / 2, (points[1].y + points[2].y) / 2, 0.0f);
glVertex3f((points[2].x + temp.x) / 2, (points[2].y + temp.y) / 2, 0.0f);
glEnd();
}
window.Display();
}
}
//g++main.cpp-lGL-lsfml图形-lsfml窗口
//使用SFML1.6
#包括
使用名称空间sf;
结构点
{
浮点x,y;//z始终为0…现在。MWUAHAHAA
};
点点[3]={{0.f,1.f},//顶部
{-1.f,-1.f},//左
{1.f,-1.f}};//正确的
点温度={点[0].x,点[0].y};
void renderFirstTriangle()
{
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
glBegin(GL_三角形);
GL3F(1.f,1.f,1.f);
glVertex3f(点[0].x,点[0].y,0.f);
GL3F(1.f,1.f,1.f);
glVertex3f(点[1].x,点[1].y,0.f);
GL3F(1.f,1.f,1.f);
glVertex3f(点[2].x,点[2].y,0.f);
格伦德();
}
int main()
{
窗口(视频模式(800600),“分形”);
window.UseVerticalSync(true);
renderFirstTriangle();
while(window.IsOpened())
{
事件;
while(window.GetEvent(event))
{
if(event.Type==event::Resized)
glViewport(0,0,event.Size.Width,event.Size.Height);
else if(event.Type==event::Closed)
window.Close();
}
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
对于(int i=0;i<2;i++)
{
//计算新的顶点位置
温度x=点[0].x;
温度y=点[0].y;
glBegin(GL_三角形);
如果(i%2)
GL3F(0.1f、0.1f、0.1f);
glVertex3f((点[0].x+点[1].x)/2,(点[0].y+点[1].y)/2,0.0f);
glVertex3f((点[1].x+点[2].x)/2,(点[1].y+点[2].y)/2,0.0f);
glVertex3f((点[2].x+temp.x)/2,(点[2].y+temp.y)/2,0.0f);
格伦德();
}
window.Display();
}
}
Hi。谢谢你的回复。我尝试过这个,但是当我让屏幕只显示循环的数据时