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

Author Topic: pushGLStates/popGLStates? (Fixed)  (Read 1295 times)

0 Members and 1 Guest are viewing this topic.

SpectreNectar

  • Newbie
  • *
  • Posts: 39
    • View Profile
pushGLStates/popGLStates? (Fixed)
« on: May 05, 2013, 11:06:07 pm »
EDIT: Nevermind it was culling that caused this ._.

Hi...

I need a bit of help figuring out how to use the graphics module with OpenGL.

My attempt:

#include "application.h"


Application::Application(Configuration c) :
    vmode(c.width, c.height, c.depth),
    win(vmode, c.title, sf::Style::Default, c.gfx),
    fpsTimer(),
    deltaTimer() {

    // INITIALIZE
    win.setVerticalSyncEnabled(true); // call it once, after creating the window
    // OR win.setFramerateLimit(60);  // --||--

    Input::init();

    is_running = true;

    // SETUP

    game = new Game(c.width, c.height);

    //OPENGL

     // Create a sprite for the background


    texture = 0;
    {
        sf::Image image;
        if (!image.loadFromFile("data/gfx/crate.bmp"))
            is_running = false;
        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    }

     // Setup an ortographic projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
   
    glOrtho(0.0, c.width, 0.0, c.height, -1.0, 1.0);
    glViewport(0, 0, c.width, c.height);

    //Culling
    glEnable(GL_CULL_FACE);
    glFrontFace(GL_CCW);
    glCullFace(GL_BACK);

    glColor4f(1.f, 1.f, 1.f, 1.f);

    // MISC

        //ALpha
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    config = c;

}

Application::~Application() {

    // Don't forget to destroy the texture
    glDeleteTextures(1, &texture);

    //oss.str(""); //DO THIS IF DRAWING TEXT

    delete game;
}


void Application::run() {

    while (is_running)
    {

                // E V E N T S
       
        // Handle inp presses or releases
        Input::frame();

        sf::Event event;
        while (win.pollEvent(event))
        {

            Input::sync(event);

            switch(event.type) {
                case sf::Event::Closed:
                    // Window closed
                    is_running = false;
                break;
                case sf::Event::Resized:
                    // adjust the viewport when the window is resized
                    glViewport(0, 0, event.size.width, event.size.height);
                break;
                case sf::Event::KeyReleased:
                    // ESC released
                    if(event.key.code==sf::Keyboard::Escape) is_running = false;
                break;
                default:
                break;

            }
        }

                // L O G I C
               
        double fps = 0;
        double framerate = fpsTimer.getElapsedTime().asSeconds();
        if(framerate>0.0) fps = 1.0/framerate;
        else fps = config.fps;
        fpsTimer.restart();

        game->update(deltaTimer.getElapsedTime().asMilliseconds());

               
                // G F X
               
                // Activate the first window
        win.setActive(true);
               
               
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        game->drawGL(win);
        win.pushGLStates();
        game->drawSFML(win);
        win.popGLStates();
        win.display();

    }

}
 

It draw the OpenGL graphics but seemingly the OpenGL graphics is either the only thing drawn or is drawn after the SFML graphics.

Any hints?

Also it would be nice with a page about it on the wiki .

EDIT: Nevermind it was culling that caused this ._.
« Last Edit: May 05, 2013, 11:46:41 pm by SpectreNectar »