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

Author Topic: Having trouble trying to make SFML and OpenGL work.  (Read 180 times)

0 Members and 1 Guest are viewing this topic.

nickklis

  • Newbie
  • *
  • Posts: 4
    • View Profile
Having trouble trying to make SFML and OpenGL work.
« on: December 28, 2023, 07:39:37 am »
I am having trouble making SFML and OPENGL to work together.

The program boots but I cant get a shape to show in the window.

Here is the code:

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

const GLint SCREEN_WIDTH = 500, SCREEN_HEIGHT = 500;



int main()
{
    std::cout << "Hello World!\n";

    sf::ContextSettings settings;
    settings.depthBits = 24;
    settings.stencilBits = 8;
    settings.majorVersion = 4.5;
    //settings.minorVersion = 0;
   // settings.majorVersion = 3;
    settings.minorVersion = 3;
    settings.attributeFlags = sf::ContextSettings::Core;

    sf::Window window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "WINDOW", sf::Style::Titlebar | sf::Style::Close | sf::Style::Resize, settings);

    glewExperimental = GL_TRUE;

    if (GLEW_OK != glewInit())
    {
        std::cout << "GLEW FAIL" << std::endl; std::cout << "GLEW FAIL" << std::endl; std::cout << "GLEW FAIL" << std::endl;

        return EXIT_FAILURE;
    }

    bool RUN = true;

    while (RUN)
    {
        sf::Event windowEvent;

        while (window.pollEvent(windowEvent))
        {
            switch (windowEvent.type)
            {
            case sf::Event::Closed:
                    RUN = false;

                    break;
            }
        }

     

       // glClearColor(0, 0, 0, 0);
       // glClear(GL_COLOR_BUFFER_BIT);
      //  window.clear();
       

         /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);


        glBegin(GL_TRIANGLES);
        glVertex2f(-0.7, -0.5);
        glVertex2f(0.7, -0.5);
        glVertex2f(0, 0.7);
        glEnd();



        window.display();

    }

    window.close();

    return EXIT_SUCCESS;

}

« Last Edit: December 30, 2023, 12:53:00 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Having trouble trying to make SFML and OpenGL work.
« Reply #1 on: December 30, 2023, 12:54:21 pm »
I don't see you adjust the projection matrix (i.e. the "camera") anywhere.

Maybe the official SFML OpenGL example can help: https://github.com/SFML/SFML/blob/master/examples/opengl/OpenGL.cpp
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/