I've been working on a 3D application using SFML for context creation and OpenGL 3.0. For some reason when I attempt to create the context using OpenGL 3.0 it seems to draw the image slightly narrowed and doubled with a black bar in between, and the screen seems to be cleared with green instead of red for some reason. If I change the context to 2.1 it draws normally. Originally I was having this problem using modern OpenGL code but I've provided a sample using the fixed function pipeline so that the problem is clearer.
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
// create the window
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 4;
settings.majorVersion = 3;
settings.minorVersion = 0;
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, settings);
// load resources, initialize the OpenGL states, ...
glClearColor(1.0, 0.0, 0.0, 1.0);
// run the main loop
bool running = true;
while (running)
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
}
// clear the buffers
glClear(GL_COLOR_BUFFER_BIT);
// draw...
glBegin(GL_TRIANGLES);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f(-1.0,-1.0, 0.0);
glVertex3f( 1.0,-1.0, 0.0);
glEnd();
// end the current frame (internally swaps the front and back buffers)
window.display();
}
return 0;
}
If I Change these two lines:
settings.majorVersion = 3;
settings.minorVersion = 0;
To these:
settings.majorVersion = 2;
settings.minorVersion = 1;
The window draws normally.
Here are screenshots of what is happening.
(http://i.imgur.com/MR6Tjik.png)
(http://i.imgur.com/NYtLQr9.png)
The second image is a little messed up because my computer lagged. It shouldn't have that orange tone.
My setup is:
Ubuntu 12.10 Intel i7-3630QM Intel HD Graphics 4000
From glxinfo: OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile OpenGL version string: 3.0 Mesa 9.0.2 OpenGL shading language version string: 1.30
From lspci: Kernel driver in use: i915
I thought this might be a driver issue but I've had success running OpenGL 3.0 programs using GLUT and no deprecated functionality so it must have been creating a valid OpenGL 3.0 context and working.
I'm very confused as to why this is happening.
i get something very similar to matjoeman's problem with the same type of opengl functions.
I'm using ubuntu 13.04 beta and have updated my ATI drivers to 13.3 beta..
Seeing his post i set the opengl version to 2.1 like he did but got no improvements. Here is my code
#include<SFML/Window.hpp>
#include<GL/gl.h>
#include<SFML/OpenGL.hpp>
int main()
{
sf::ContextSettings settings;
settings.majorVersion = 1;
settings.minorVersion = 1;
settings.depthBits = 24;
settings.stencilBits = 8;
sf::Window window(sf::VideoMode(1024,768,), "OpenGL Fullscreen Window",sf::Style::Fullscreen);
window.setVerticalSyncEnabled(true);
bool running = true;
while (running)
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit by pressing x button on window
if (event.type == sf::Event::Closed)
{
running = false;
}
if(event.key.code == sf::Keyboard::Escape)//close by
// hitting escape key
{
running = false;
}
if (event.type == sf::Event::Resized)//resizing
{
glViewport(0,0,event.size.width,event.size.height);
}
}
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//glClearColor(1.0f,0.0f,0.0f,1.0f);
glColor3f(1.0f,1.0f,0.0f);
glRectf(-5.0f,5.0f,5.0f,-5.0f);
glFlush();
//engine bo;
//bo.drawrectangle();
window.display();
}
return 0;
}
The error i get is that when i try to draw a rectangle it either fills the screen with the color i chose for the rectangle or the
glClearColor(); function overrides the rectangle and so i can't see the rectangle or its color. there was one occasion though that i
was seeing two colors on screen but it split the screen in half. One half of the screen was the rectangle color and the other the glClearColor function.
Have not tried to use freeglut yet, and i'm learning this stuff for the first time using a opengl book.