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

Author Topic: [Fixed] Custom GL on RenderTarget without Sprites  (Read 1909 times)

0 Members and 1 Guest are viewing this topic.

LittleFox

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
[Fixed] Custom GL on RenderTarget without Sprites
« on: April 28, 2014, 11:27:18 pm »
Hi there,

I'm currently facing the following problem:

I do some custom GL rendering mixed with SFML Shapes. When I have shapes on the RenderTarget my custom GL code works just fine, but without shapes (and so without any call to RenderTarget::draw(sf::Drawable)) the screen stays black.

Is there anything I have to initialize? I've already searches through the SFML Code but couldn't find anything...

Greetings,
LittleFox
« Last Edit: April 29, 2014, 08:54:37 pm by LittleFox »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11037
    • View Profile
    • development blog
    • Email
AW: Custom GL on RenderTarget without Sprites
« Reply #1 on: April 28, 2014, 11:31:51 pm »
Create a minimal and complete example, so we see what you're really doing. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

LittleFox

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Custom GL on RenderTarget without Sprites
« Reply #2 on: April 28, 2014, 11:50:07 pm »
Here it is:
http://pastebin.com/tWiThNQU

Thank you for your fast answer :)

(oh and I know it should be drawn, not drawed^^)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Custom GL on RenderTarget without Sprites
« Reply #3 on: April 28, 2014, 11:54:16 pm »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

LittleFox

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Custom GL on RenderTarget without Sprites
« Reply #4 on: April 28, 2014, 11:56:44 pm »
resetGLStates() before clear() does not fix it, I've just tried
« Last Edit: April 29, 2014, 12:18:32 am by LittleFox »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Custom GL on RenderTarget without Sprites
« Reply #5 on: April 29, 2014, 02:13:38 am »
You can't expect SFML to set OpenGL up for you. It will only do so if it has to, i.e. if it has to draw something.
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

int main(int argc, char* argv[])
{
        sf::RenderWindow window(sf::VideoMode(800, 600), sf::String("SFML noShapeGL"), sf::Style::Default, sf::ContextSettings(32,0,8,4,2));
        window.setFramerateLimit(60);

        while(window.isOpen())
        {
                sf::Event event;
                while(window.pollEvent(event))
                {
                        switch(event.type)
                        {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                        }
                }

                window.clear(sf::Color(0, 0, 0));

                // SFML rendering
                //window.resetGLStates();
                // draw your SFML stuff here

                // set up GL
                glViewport(0, 0, 800, 600);
                glMatrixMode(GL_TEXTURE);
                glLoadIdentity();
                glMatrixMode(GL_PROJECTION);
                glLoadIdentity();
                glOrtho(0, 800, 600, 0, -1, 1);
                glMatrixMode(GL_MODELVIEW);

                // custom GL-Rendering
                glPushMatrix();
                glLoadIdentity();
                glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT);
                glColor4f(1.0, 0, 0, 1.0);
                glLineWidth(5);

                glBegin(GL_LINES);
                {
                        glVertex2d(10, 50);
                        glVertex2d(50, 10);
                }
                glEnd();

                glPopAttrib();
                glPopMatrix();

                window.display();
        }
}
If you want to program using OpenGL, you should have basic knowledge about how to set up the viewport and the required matrices. If you don't understand any of these concepts, I strongly suggest you read up about them somewhere on the internet. Your usage of GL_TRANSFORM_BIT is also incorrect. It doesn't push the transformation matrices as you might expect. The matrix stack has its own push and pop functions. This is also explained in beginner OpenGL tutorials.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

LittleFox

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Custom GL on RenderTarget without Sprites
« Reply #6 on: April 29, 2014, 08:54:18 pm »
Hi,

hmm ... I had expected SFML sets these on initialization. Thanks for pointing that out.
Also thanks for glPushMatrix - I didn't know that one.

Greetings,
LittleFox