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

Pages: [1]
1
Graphics / Re: Can't change position of sf::Sprite
« on: March 30, 2020, 08:23:27 pm »
Thanks for your reply! I actually saw that page, but I guess I just have a misunderstanding of how OpenGL works and what "states" are. I've only ever used OpenGL by itself and not in combination with a second graphics library. I'll do a little more research on OpenGL and then come back to this project. :)

2
Graphics / Can't change position of sf::Sprite
« on: March 28, 2020, 10:03:28 pm »
Hello! I'm trying to set up SFML with GLEW so I can directly use OpenGL calls instead of being limited to the SFML graphics package. As a simple test, I tried to render a single triangle to a sf::RenderTexture, and then render that texture onto a sf::RenderWindow by attaching it to a sf::Sprite. My triangle rendered correctly at first, but then I tried adding in some code to make the sprite move around, but the code seemed to have no effect and my triangle still rendered to stretch across the whole screen. This makes me wonder if I'm really rendering to the RenderTexture or if I'm somehow rendering my triangle directly to the window without realizing it. Anyway, here's my code:

#include <gl/glew.h>

#include <SFML/Graphics.hpp>
#include <iostream>

#include "Shader.h"

int main()
{

        sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL 4.3", sf::Style::Default);
        window.setVerticalSyncEnabled(true);

        sf::ContextSettings settings;
        settings.majorVersion = 4;
        settings.minorVersion = 3;
       
        sf::RenderTexture gl_renderTarget;
        gl_renderTarget.create(800, 600, settings);
        gl_renderTarget.setActive(true);
       
        sf::Sprite gl_rendering(gl_renderTarget.getTexture());

        if (glewInit() != GLEW_OK)
        {

                std::cout << "Failed to initialize GLEW.\n";

                int qqq; std::cin >> qqq;
                return -1;

        }

        // Just a simple class that I wrote for handling shaders
        ShaderProgram shader("shader.vs", "shader.fs");

        GLfloat verts[] = {
                -1.0f, -1.0f,
                1.0f, -1.0f,
                1.0f, 1.0f
        };
       
        GLuint vao;
        glGenVertexArrays(1, &vao);
        glBindVertexArray(vao);

        GLuint vbo;
        glGenBuffers(1, &vbo);
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);

        glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
        glEnableVertexAttribArray(0);

        glBindVertexArray(0);

        while (window.isOpen())
        {

                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                gl_renderTarget.setActive(true);

                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glBindVertexArray(vao);
                shader.use();
                glDrawArrays(GL_TRIANGLES, 0, 3);
               
                // As far as I understand, this should be making the triangle rotate every iteration, but instead it is stationary
                gl_rendering.rotate(10.0f);
                window.draw(gl_rendering);

                window.display();

        }

        return 0;
}
 

Any help would be greatly appreciated  :D I don't usually ask for help on forums like this, but I've been stuck on this for hours and I don't think I'm gonna figure it out anytime soon. This is my first time using SFML, so I'm sorry if it's something super obvious that I'm just overlooking.

Pages: [1]