Sign in to follow this  
TSM

opengl front / back buffer problems? (simple example inside)

Recommended Posts

Hey guys.

I'm re-sharpening my OpenGL stone, and I've hit a problem that has stumped both myself and my internet researching skills. It's probably very simple.

The problem is once I run my application, the application's viewport flashes between two renders in a flickering pattern. I'm supposing the front and back buffers are swapping.

How can I prevent this? I want all the triangles to stay on screen at all times. I'm certain it has to do with my if/else statment followed by window.display(), which is from SFML 2.0rc.

I'm working on a Sierpinski Gasket (I'm close but not done yet. Don't tell me I want to figure it out!). I am interested in general code clean up though. I'm open for any suggestions!

Thanks!

P.S my edits are code clean ups and exipirments to fix the issue. I'm still hunting!

[source lang="cpp"]
#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();
}
}[/source] Edited by TSM

Share this post


Link to post
Share on other sites
I know you probably don't want to hear this, but using a Grammar L-system will be more robust. Not only that but most fractals can be generated this way more easily.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this