So first of all are there any good tutorials for using SFML 2.1 and OpenGL 4.2? Most seem to be pretty outdated, so I figured I would ask here for help.
So far I have a basic program that creates a window and outputs OpenGL settings used:
#include<iostream>
#include<thread>
#include<cstdint>
#include<SFML/System.hpp>
#include<SFML/Window.hpp>
#include<SFML/Graphics.hpp>
#include<SFML/Audio.hpp>
#include<SFML/Network.hpp>
#include<SFML/OpenGL.hpp>
int main(){
const float windowScale=0.75f;
sf::ContextSettings settings;
settings.depthBits=24;
settings.stencilBits=8;
settings.antialiasingLevel=32;
settings.majorVersion=4;
settings.minorVersion=2;
sf::Window window(
sf::VideoMode(
static_cast<unsigned int>(sf::VideoMode::getDesktopMode().width*windowScale),
static_cast<unsigned int>(sf::VideoMode::getDesktopMode().height*windowScale)
),
"OpenGL",
sf::Style::Default,
settings
);
window.setPosition(
sf::Vector2i(
sf::VideoMode::getDesktopMode().width/2-window.getSize().x/2,
sf::VideoMode::getDesktopMode().height/2-window.getSize().y/2
)
);
window.setVerticalSyncEnabled(true);
settings=window.getSettings();
std::cout<<"OpenGL Settings\n";
std::cout<<"Depth bits: "<<settings.depthBits<<'\n';
std::cout<<"Stencil bits: "<<settings.stencilBits<<'\n';
std::cout<<"Antialiasing level: "<<settings.antialiasingLevel<<'\n';
std::cout<<"Version: "<<settings.majorVersion<<'.'<<settings.minorVersion<<'\n';
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
switch(event.type){
case sf::Event::Closed:
window.close();
break;
case sf::Event::Resized:
glViewport(0,0,event.size.width,event.size.height);
break;
default:
break;
}
}
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
window.display();
}
return EXIT_SUCCESS;
}
If there are any tips to improve my code; that would be greatly appreciated.
I would like to start out by making a cube function, that takes a position(x,y,z), a color(RGBA), and a texture(png) as input.
Using a geometry shader, I would like to take the position to transform it into a cube; does sf::shader support geometry shaders currently?
As for the color and texture, I would like these to be optional if the other is given, or if both are given, the color is multiplied to the texture. So if only a color is given, the cube would simply be a solid color, or if just a texture is given, the texture is used as is. So I would assume I would do this using overloaded functions right?