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.


Topics - sodah

Pages: [1]
1
Graphics / Drawing to renderTextures
« on: May 11, 2018, 12:08:01 am »
Hey,

I am doing some simulations with autonomous agents that are controlled by an artificial neural network.
The input into the ANNs is the world rendered from their perspective i.e a renderTexture with a corresponding view.

Since i'm new to SFML i'm not sure how to do this in the fastest way possible.
My current way is just simply:

renderTexture.setView(...);
renderTexture.draw(...);
image = renderTexture.getTexture().copyToImage();
... feed pixels to ANN

Is there anyway to do this with better performance or do you have any better approach?

2
Graphics / GL_INVALID_OPERATION when pushGLStates()
« on: June 03, 2013, 08:29:33 pm »
So, im just starting GL with sfml. When i try to pushGLStates to draw a simple circle i get GL_INVALID_OPERATION in current state in the console.

My textured quad i try to draw afterwards comes out fine.

the problems starts when i bind my first vertexarray at line 43
//OpenGL
#include <gl\glew.h>
#include <gl\freeglut.h>
#include <glm\glm.hpp>
#include <glm\ext.hpp>

//SFML
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML\OpenGL.hpp>

//Std
#include <string>
#include <iostream>

//Stuff
#include "ShaderManager.hpp"
#include "Convertion.hpp"

//test
#include "Cube.hpp"
int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL");

        GLenum GlewInitResult;
        GlewInitResult = glewInit();

        if (GLEW_OK != GlewInitResult) {
                fprintf(
                        stderr,
                        "ERROR: %s\n",
                        glewGetErrorString(GlewInitResult)
                );
                exit(EXIT_FAILURE);
        }
        sf::Clock clock;

        GLuint program = ShaderManager::LoadShaders("Simple_vertex.glsl", "Simple_fragment.glsl");
       
        GLuint VertexArrayID;
        glGenVertexArrays(1, &VertexArrayID);
        glBindVertexArray(VertexArrayID);

        Cube* cube = new Cube();
       
        // This will identify our vertex buffer
        GLuint vertexbuffer;
        // Generate 1 buffer, put the resulting identifier in vertexbuffer
        glGenBuffers(1, &vertexbuffer);
        // The following commands will talk about our 'vertexbuffer' buffer
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        // Give our vertices to OpenGL.
        glBufferData(GL_ARRAY_BUFFER, cube->getVertices().size() * sizeof(float), &cube->getVertices()[0], GL_STATIC_DRAW);

        static const GLfloat g_uv_buffer_data[] = {
                1.0, 1.0,
                0.0, 1.0,
                0.0, 0.0,

                0.0, 0.0,
                1.0, 0.0,
                1.0, 1.0 };

        // This will identify our vertex buffer
        GLuint UVbuffer;
        // Generate 1 buffer, put the resulting identifier in vertexbuffer
        glGenBuffers(1, &UVbuffer);
        // The following commands will talk about our 'vertexbuffer' buffer
        glBindBuffer(GL_ARRAY_BUFFER, UVbuffer);
        // Give our vertices to OpenGL.
        glBufferData(GL_ARRAY_BUFFER, sizeof(g_uv_buffer_data), g_uv_buffer_data, GL_STATIC_DRAW);
    // load resources, initialize the OpenGL states, ...

        glm::mat4 Projection = glm::perspective(75.0f, 4.0f/3.0f, 0.1f, 100.0f);
        glm::mat4 View = glm::lookAt(glm::vec3(0,0,-10), glm::vec3(0,0,0), glm::vec3(0,1,0)); // pos, looking at, upvector
        glm::mat4 Model = glm::mat4(1.0f);
        glm::mat4 MVP = Projection * View * Model;

        GLuint MatrixID = glGetUniformLocation(program, "MVP");

        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);
        glClearDepth(1.f);

        glEnable(GL_TEXTURE_2D);

    GLuint texture = 0;
    {
        sf::Image image;
        if (!image.loadFromFile("lolcat.png"))
            return EXIT_FAILURE;

        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    }

        glBindTexture(GL_TEXTURE_2D, texture);

        GLuint TextureID  = glGetUniformLocation(program, "textureSampler");
        glUniform1i(TextureID, 0);

        sf::CircleShape shape(50);
        shape.setFillColor(sf::Color(100,250,20));

        // run the main loop
    bool running = true;
    while (running)
    {
        // handle events
        sf::Event Event;
        while (window.pollEvent(Event))
        {
            if (Event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (Event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, Event.size.width, Event.size.height);
            }
        }

        // clear the buffers
        glClear(GL_DEPTH_BUFFER_BIT);

                // 1rst attribute buffer : vertices
                glEnableVertexAttribArray(0);
                glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
                glVertexAttribPointer(
                        0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
                        3,                  // size
                        GL_FLOAT,           // type
                        GL_FALSE,           // normalized?
                        0,                  // stride
                        (void*)0            // array buffer offset
                );

                // UV
                glEnableVertexAttribArray(1);
                glBindBuffer(GL_ARRAY_BUFFER, UVbuffer);
                glVertexAttribPointer(
                        1,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
                        2,                  // size
                        GL_FLOAT,           // type
                        GL_FALSE,           // normalized?
                        0,                  // stride
                        (void*)0            // array buffer offset
                );

                glUseProgram(program);
                glUniformMatrix4fv(MatrixID,1,GL_FALSE, &MVP[0][0]);

                // Draw the triangle !
                glDrawArrays(GL_TRIANGLES, 0, 6); // Starting from vertex 0; 3 vertices total -> 1 triangle
 
                glUseProgram(0);

        // end the current frame (internally swaps the front and back buffers)

                window.pushGLStates();
                window.draw(shape);
                window.popGLStates();
               
                window.display();
    }

    // release resources...

    return 0;
}
 

Any help would be appriciated :-)

3
Window / Open GL sfml 2.0
« on: August 08, 2012, 07:23:14 pm »
Hi!

Just started trying to use sfml2 with openGL.
The examples worked fine and all but when i tried to convert
this tutorial: http://openglbook.com/the-book/chapter-4-entering-the-third-dimension/
to sfml from glut i cant get it to work.

if i disable the shaders, aka just making them fail to load i see a white square. So i guess
it got nothing to do with SFML.

Anyone got any other super-easy examples that uses buffer objects that work easily with sfml?

And are there any restrictions on what openGL features i can use with SFML ?

Cheers
sodah

Pages: [1]
anything