Hi,
I have trying to use SFML as a window context for OpenGL, but i get a black screen when i run the code
I have tried different code, but i still get the same result, when i run the same code using glut, it displays
NB: this is the same thing that happens when i run SDL+OpenGL
/*
* Main.cpp
*
* Created on: Sep 20, 2015
* Author: Damian-Machine
*/
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <math.h>
#include<iostream>
#define PI 3.14159265f
GLdouble clipAreaXLeft, clipAreaXRight, clipAreaYBottom, clipAreaYTop;
bool fullScreenMode = true; // Full-screen or windowed mode?
void initGL(){
/*glClearColor(1.0 ,0.0, 0.0, .0);*/
// Set color and depth clear value
glClearDepth(1.f);
glClearColor(1.f, 1.f, 1.f, 1.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
}
void display(){
//glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -2.f);
glBegin(GL_QUADS);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);
glEnd();
}
void reshape(GLsizei width, GLsizei height){
if(height == 0) height = 1;
GLfloat aspect = (GLfloat)width / (GLfloat)height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width >= height) {
clipAreaXLeft = -1.0 * aspect;
clipAreaXRight = 1.0 * aspect;
clipAreaYBottom = -1.0;
clipAreaYTop = 1.0;
} else {
clipAreaXLeft = -1.0;
clipAreaXRight = 1.0;
clipAreaYBottom = -1.0 / aspect;
clipAreaYTop = 1.0 / aspect;
}
gluOrtho2D(clipAreaXLeft, clipAreaXRight, clipAreaYBottom, clipAreaYTop);
}
int main(){
sf::ContextSettings settings;
settings.depthBits = 32;
settings.stencilBits = 8;
settings.antialiasingLevel = 4;
//settings.majorVersion = 2;
//settings.minorVersion = 1;
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, settings);
window.setVerticalSyncEnabled(true);
window.setActive(true);
// load resources, initialize the OpenGL states, ...
// run the main loop
bool running = true;
initGL();
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);
reshape(event.size.width, event.size.height);
}
}
// clear the buffers
display();
// end the current frame (internally swaps the front and back buffers)
window.display();
}
// release resources...
return 0;
}