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

Author Topic: Why does SFML with an Opengl 3.0 context draw twice?  (Read 5681 times)

0 Members and 1 Guest are viewing this topic.

matjoeman

  • Newbie
  • *
  • Posts: 2
    • View Profile
Why does SFML with an Opengl 3.0 context draw twice?
« on: April 14, 2013, 04:01:12 am »
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.




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.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Why does SFML with an Opengl 3.0 context draw twice?
« Reply #1 on: April 14, 2013, 07:22:03 am »
Many things could be wrong but never the glClearColor()!!!

I was looking at your problem trying to come up with an idea about it.. try not rendering the triangle, only clear and display, and check if the background is red or not. Also try to move the clear color to the loop, just for paranoia.

Its very weird because you re doing it right i believe, at least the clear color should work out of the box, its the simplest thing you can do, and there is no other direct way of asking a "red" fill color i believe..

I bet my penny on that your graphics card is not updated or simply is bugged somehow..

matjoeman

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Why does SFML with an Opengl 3.0 context draw twice?
« Reply #2 on: April 15, 2013, 08:14:49 am »
I repeated the test without drawing the triangles and the error is the same. glClear draws the wrong color and there is still the black bar. I also tried with glClearColor set to red and in the OpenGL 3.0 context it drew magenta which again is incorrect.

I repeated the test under Arch Linux with Mesa 9.1.1 and got the same results.

I wrote another test using freeglut and glutinitcontextversion to 3.0 and there were no issues, so I think this is somehow an SFML problem.

kerp

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Why does SFML with an Opengl 3.0 context draw twice?
« Reply #3 on: April 15, 2013, 10:32:43 am »
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.
a noob in training...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Why does SFML with an Opengl 3.0 context draw twice?
« Reply #4 on: April 15, 2013, 11:46:42 am »
@matjoeman: I'd still blame the driver. Although it might work with some of the context creation, it seems to fail with some others. For my Windows 8 x64 AMD Readon HD 7500M/7600M it works perfectly fine.



@kerp: You're code is errorous. You have comma within the VideoMode, which isn't followed by a bpp and although you setup some settings, you don't apply them at window creation. Besides that you're specifying OpenGL 1.1 - is this intended?
For the OpenGL part, I don't know if the code is written correctly, since I've no experience with. When I build and run it (with the corrections mentioned above) I get a yellow screen.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Why does SFML with an Opengl 3.0 context draw twice?
« Reply #5 on: April 15, 2013, 12:45:38 pm »
If it worked in Glut but not in SFML, unless something is slipping under the hood its not a driver issue directly for OpenGL 3.0. Must be the compatibility profile that sfml always requests which doesn't work so good in your GPU.

I believe there is nothing you can do about it. SFML contexts were not designed to support latest OpenGL features if im not mistaken.

kerp

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Why does SFML with an Opengl 3.0 context draw twice?
« Reply #6 on: April 15, 2013, 04:48:33 pm »
hello again,
@exploit3r
Sorry about the errors i was playing around with it when i posted. I fixed the errors and yes it does produce yellow screen.

Since i am a noob and don't want to hijack this thread i will bow out. But i was puzzling over why i could'nt follow my opengl  book
like i thought i could and use sfml to create windows, matjoeman was doing and thought maybe there was something i could
contribute.

Anyway i switched over to linux mint 14 nadia and still am puzzled. at my individual problem. but i will post another thread if i have troubles later.
a noob in training...