Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Jesse Meyer

Pages: [1]
1
Graphics / Re: back buffering problem?
« on: October 02, 2012, 08:34:16 am »
Thanks! (Btw, what would be the next popular alternative to what I'm doing?)

2
Graphics / Re: back buffering problem?
« on: October 01, 2012, 11:57:11 pm »
It's a Sierpinski Gasket fractal generator.

3
Graphics / Re: back buffering problem?
« on: October 01, 2012, 11:08:34 pm »
Ha. Well as it stands, it works, but with a huge caveat that the screen blinks sometimes between two different sets of points (flipping buffers). To address this, I'd have to store each new point generated per frame into a container (a persistent object) and iterate through it each frame. The obvious downside is that as the object grows so does the time it takes to render. The longer the application runs the slower it becomes.

4
Graphics / Re: back buffering problem?
« on: October 01, 2012, 10:24:22 pm »
Thanks Laurent. I'm still figuring out SFML (and it's bloody fantastic thus far, great job!), which leads to another question : is there a persistent object within SFML that I can use for storing these points, or is something as generic as <vector> good enough?

5
Graphics / Re: back buffering problem?
« on: October 01, 2012, 07:03:39 am »
Thanks everyone.

So, I'm using RenderWindow now, along with window.clear() and I am in need of some advice.

As expected, the back buffer clears but with that so do all the points that have been rendered thus far. What is the best design to ensure the dots remain on screen? Do I have to re-render them each frame, implying that the longer my application runs, the longer each frame will take to render? I don't forsee that being an issue but it does complicate the code.

My code now is as follows :

#include <SFML/Graphics.hpp>
#include <GL/glew.h>
#include <time.h>
#include <iostream>

using namespace sf;

struct point
{
        float x, y; // z is always 0 ... for now. MWUAHAHAA
};
                   //  x  ,  y
point triangle[3] = {{-1.f, -1.f},      // left
                                    { 1.f, -1.f},      // right
                                    { 0.f, 1.f}};     // top

int main()
{
    RenderWindow window(VideoMode(800, 600), "Fractal", Style::Default, ContextSettings(32));
    window.setVerticalSyncEnabled(true);

        srand((unsigned)time(0));

        float oldX = (float)rand()/((float)RAND_MAX / 2 );
        float oldY = (float)rand()/((float)RAND_MAX / 2 );

        // normalize the result
        if((oldX + oldY) > 2)
        {
                oldX -= 1.f;
                oldY -= 1.f;
        }

        int randomVertex;
        float newX;
        float newY;

        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();
        }

                window.clear();

                // calculate new vertex positions

                randomVertex = rand() % 3;

                newX = (oldX + triangle[randomVertex].x) / 2;
                newY = (oldY + triangle[randomVertex].y) / 2;

                glBegin(GL_POINTS);

                glVertex3f(newX, newY, 0.0f);

                glEnd();

                oldX = newX;
                oldY = newY;
               
                window.display();
        }
}

6
Graphics / Re: back buffering problem?
« on: September 30, 2012, 06:08:54 am »
Thanks for the response.

I am using SFML 2.0 and window.clear does not exist in 2.0. I have added window.setActive(); though which doesn't seem to help but seems appropiate.

I'm beginning to presume this is a problem with 2.0 itself. Thoughts anyone?

I will also note that moving a window infront of my application in windows 7 does not clear the screen. So, the data is being stored and re-rendered it seems.

7
Graphics / back buffering problem?
« on: September 29, 2012, 04:12:43 am »
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!


#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 < 3; 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();
        }
}

Pages: [1]
anything