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 - Izman

Pages: [1]
1
Graphics / Re: Smooth movement.
« on: October 02, 2013, 10:00:20 am »
Same problem.
Only render more than 60fps make it look smooth.
If I update the movement at 30fps and render at eg. 100fps, its looks ok. Which is the reverse of what I read o.O

No, that should be correct, assuming you're using frame interpolation.

I've found that, especially at a strictly 2D level, there's a big notice in quality from 30fps to 60fps.

For example, http://boallen.com/fps-compare.html

2
Graphics / Re: [2.0] RenderWindow, GLStates, and VBOs
« on: April 06, 2013, 11:02:12 am »
Hum... I don't know how the old API (glEnableClientState) mixes with the new one (glEnableVertexAttribArray), and I can't test OpenGL 3 on my computer so I'm not sure what you should do.

Does the program give the expected result without the SFML drawing?

Well the thing is that I'm not actually drawing with SFML yet.  I just added
        window.pushGLStates();
           
            //RENDER SFML HERE

        window.popGLStates();
to state where I would theoretically put my window.draw(text) calls.

Currently, I'm just trying to get VBOs drawing while using sf::RenderWindow's pushGLStates() and popGLStates().  If I do not include those 2 functions, I get the expected result (more specifically, if I remove the resetGLStates() call all together)


On a separate note, I did find something interesting.  sf::Text doesn't draw if I call the function
glBindVertexArray( vao );
I can only see the text if I comment out that line (and the rest of the VBO init).

3
Graphics / Re: [2.0] RenderWindow, GLStates, and VBOs
« on: April 05, 2013, 06:51:37 pm »
Sorry for the delay,

Considering I'm a complete beginner at VBOs, I don't really know what I can cut, so this is the smallest I can get the source code:

// Link statically with GLEW
#define GLEW_STATIC

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

// Shader sources
const char* vertexSource =
        "#version 150\n"
        "in vec2 position;"
        "in vec3 color;"
        "out vec3 Color;"
        "void main() {"
        "       Color = color;"
        "       gl_Position = vec4( position, 0.0, 1.0 );"
        "}";
const char* fragmentSource =
        "#version 150\n"
        "in vec3 Color;"
        "out vec4 outColor;"
        "void main() {"
        "       outColor = vec4( Color, 1.0 );"
        "}";

int main()
{
        int state = 1;  //IF 0 = PROGRAM ENDS
        sf::RenderWindow window( sf::VideoMode( 800, 600, 32 ), "OpenGL", sf::Style::Titlebar | sf::Style::Close );

        // Initialize GLEW
        glewExperimental = GL_TRUE;
        glewInit();

        // Create Vertex Array Object
        GLuint vao;

        glGenVertexArrays( 1, &vao );
        glBindVertexArray( vao );
       
        // Create a Vertex Buffer Object and copy the vertex data to it
        GLuint vbo;
        glGenBuffers( 1, &vbo );

        float vertices[] = {
                -0.5f,  0.5f, 1.0f, 0.0f, 0.0f, // Top-left
                 0.5f,  0.5f, 0.0f, 1.0f, 0.0f, // Top-right
                 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, // Bottom-right
                -0.5f, -0.5f, 1.0f, 1.0f, 1.0f  // Bottom-left
        };

        glBindBuffer( GL_ARRAY_BUFFER, vbo );
        glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW );

        // Create an element array
        GLuint ebo;
        glGenBuffers( 1, &ebo );

        GLuint elements[] = {
                0, 1, 2,
                2, 3, 0
        };

        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ebo );
        glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( elements ), elements, GL_STATIC_DRAW );

        // Create and compile the vertex shader
        GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER );
        glShaderSource( vertexShader, 1, &vertexSource, NULL );
        glCompileShader( vertexShader );

        // Create and compile the fragment shader
        GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
        glShaderSource( fragmentShader, 1, &fragmentSource, NULL );
        glCompileShader( fragmentShader );

        // Link the vertex and fragment shader into a shader program
        GLuint shaderProgram = glCreateProgram();
        glAttachShader( shaderProgram, vertexShader );
        glAttachShader( shaderProgram, fragmentShader );
        glBindFragDataLocation( shaderProgram, 0, "outColor" );
        glLinkProgram( shaderProgram );
        glUseProgram( shaderProgram );

        // Specify the layout of the vertex data
        GLint posAttrib = glGetAttribLocation( shaderProgram, "position" );
        glEnableVertexAttribArray( posAttrib );
        glVertexAttribPointer( posAttrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof( float ), 0 );

        GLint colAttrib = glGetAttribLocation( shaderProgram, "color" );
        glEnableVertexAttribArray( colAttrib );
        glVertexAttribPointer( colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof( float ), (void*)( 2 * sizeof( float ) ) );

        while ( state != 0 )
        {
                sf::Event windowEvent;
                while ( window.pollEvent( windowEvent ) )
                {
                        switch ( windowEvent.type )
                        {
                        case sf::Event::Closed:
                                state = 0;
                                break;
                        }
                }

                // Clear the screen to black
                glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                // Draw a rectangle from the 2 triangles using 6 indices
                glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0 );

                window.pushGLStates();
                       
                        //RENDER SFML HERE

                window.popGLStates();

                //If disabled, nothing gets drawn and no crash occurs
                glDisableClientState(GL_VERTEX_ARRAY);

                //Both has to be disabled or a crash occurs.  If GL_VERTEX_ARRAY is enabled and
                //GL_COLOR_ARRAY and GL_TEXTURE_COORD_ARRAY are disabled, then a white box is drawn
                glDisableClientState(GL_COLOR_ARRAY);
                glDisableClientState(GL_TEXTURE_COORD_ARRAY);

                window.display();

        }

        glDeleteProgram( shaderProgram );
        glDeleteShader( fragmentShader );
        glDeleteShader( vertexShader );

        glDeleteBuffers( 1, &ebo );
        glDeleteBuffers( 1, &vbo );

        glDeleteVertexArrays( 1, &vao );
}

4
Graphics / Re: [2.0] RenderWindow, GLStates, and VBOs
« on: April 05, 2013, 10:43:14 am »
Thank you for your patience,

Funny enough, the directions seem so simple yet I can't get them to work.  However, I did go through the SFML source code to find where the glEnableClientStates() were.

Turns out the call to resetGLStates() was the root of the problem.  If I copy out the source code without the resetGLStates() call at the end of popGLStates(), the program runs fine and I get colour.

However, that still doesn't solve anything, as I want to draw text using SFML's Text class. 

Note that I did try adding every permutation of
                glDisableClientState(GL_VERTEX_ARRAY);
                glDisableClientState(GL_COLOR_ARRAY);
                glDisableClientState(GL_TEXTURE_COORD_ARRAY);

After the popGLStates() call, and no luck -- I either get a white box, nothing at all, or a crash.


I guess from here the only option is to handle fonts from outside of SFML and use a sf::Window instead.

5
Graphics / Re: [2.0] RenderWindow, GLStates, and VBOs
« on: April 04, 2013, 09:46:15 pm »
Thanks for your assistance,

I put a resetGLStates() call because it's required for my Immediate Mode project (without it all the drawing gets thrown on top of the last SFML call)

I put the glDisableClientState() calls in the render loop, and now it doesn't crash :)  However, it's also not displaying any colour either (well duh, I disabled colour + textures).  However, if I remove the disabling of colour (or textures, or both)

                        //Disable Client States
                        glDisableClientState(GL_COLOR_ARRAY);
                        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

I get an instant crash again. 

Here's the render loop:

            // Clear the screen to black
                glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
                glClear( GL_COLOR_BUFFER_BIT );

                // Draw a rectangle from the 2 triangles using 6 indices
                glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0 );

                window.pushGLStates();
               
                        //RENDER SFML HERE

                        //Disable Client States
                        glDisableClientState(GL_COLOR_ARRAY);
                        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

                window.popGLStates();
                window.display();

How can I display the colour of the rectangle without crashing?

Edit: Removed SECONDARY_COLOR

6
Graphics / Re: [2.0] RenderWindow, GLStates, and VBOs
« on: April 04, 2013, 07:59:38 am »
Thanks for the reply :)

Sadly, I already tried doing that, but maybe I did it wrong.

Here's the exact source code I'm using.  I added in the glDisableClientState() calls after the RenderWindow

Should compile by linking GLEW statically and SFML 2.0 dynamically.

http://pastebin.com/7hWy91ff

7
Graphics / [2.0] RenderWindow, GLStates, and VBOs
« on: April 04, 2013, 02:32:42 am »
I get a crash whenever I call a GLStates() function (pushGLStates(), popGLStates(), resetGLStates()) while drawing using a VBO on a RenderWindow.

I'm trying to teach myself non-deprecated OpenGL by following the online tutorial at http://open.gl

I copy + pasted the code found in the first tutorial (located at: http://open.gl/content/code/c2_triangle_elements.txt)

I Imported
#include <SFML/Graphics/RenderWindow.hpp>
changed the syntax to match SFML 2.0, and changed the rendering code to:

    // Clear the screen to black
        glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT );
               
        // Draw a rectangle from the 2 triangles using 6 indices
        glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0 );

        window.pushGLStates();
               
                //RENDER SFML

        window.popGLStates();
        window.display();
        window.resetGLStates();

The program runs for a fraction of a second, then gives me a unhandled exception.

If I comment out 
window.pushGLStates();
window.popGLStates();
window.resetGLStates();
Then the code runs fine.  However, I want to be able to draw text using SFML along side VBOs.

I'm a total noob to VBOs, and I only come from a background of Immediate Mode.  I saw on some other threads that they used
glDisableClientState()
to fix this, but I don't know where to begin.

How can I get the tutorial code to not crash immediately?

Pages: [1]
anything