1
General / 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:
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;
}
#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;
}