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

Author Topic: Graphics system and texture questions  (Read 2199 times)

0 Members and 1 Guest are viewing this topic.

Lacrymology

  • Newbie
  • *
  • Posts: 4
    • View Profile
Graphics system and texture questions
« on: February 26, 2012, 08:27:30 pm »
I'm starting up with this, and I'm having a little 2D issue: how to draw a sprite on a
Code: [Select]
sf::RenderWindow so it has its texture's original size regardless of window resizing?

What about having it render over the whole screen, stretching as necessary?

here's my code:
Code: [Select]

void handleEvents(sf::Window &App) {
    // Process events
    sf::Event Event;
    while (App.GetEvent(Event))
    {
        // Close window : exit
        if (Event.Type == sf::Event::Closed)
            App.Close();

        // Escape key : exit
        if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            App.Close();

        // Resize event : adjust viewport
        if (Event.Type == sf::Event::Resized)
            glViewport(0, 0, Event.Size.Width, Event.Size.Height);

    }

}

void glPerFrame() {
    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

int main() {
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML OpenGL");

    sf::Image depthBuffer;

    // Start game loop
    while (App.IsOpened())
    {
        handleEvents(App);

        // Set the active window before using OpenGL commands
        // It's useless here because active window is always the same,
        // but don't forget it if you use multiple windows or controls
        App.SetActive();

        glPerFrame();

        // Use the depth buffer as texture
        updateDepthBuffer(depthBuffer);    // This takes a Kinect depth image stream and unpacks it into the provided sf::Image
        sf::Sprite dbSprite(depthBuffer);
        float appW = App.GetWidth(), appH = App.GetHeight();
        dbSprite.Resize(appW, appH);
        App.Draw(dbSprite);
        dbSprite.SetScale(1,1);
        App.Draw(dbSprite);

        // Finally, display rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


This only looks right (this is, the first call to Draw draws over the whole window, and the second draws on the depthBuffer original size) when the window has the original size it was created with: if I make it bigger, both images get stretched, so the bigger one escapes the window, and the smaller one becomes bigger, and if I make it smaller I end up with black borders.

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Graphics system and texture questions
« Reply #1 on: February 26, 2012, 11:04:58 pm »
so you want to keep the aspect ratio? scale the image by the smallest (width or height of the window), then position it by the largest minus the smallest divided by two (assuming you want to maintain the centre position), hope this helps! :D
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Lacrymology

  • Newbie
  • *
  • Posts: 4
    • View Profile
Graphics system and texture questions
« Reply #2 on: March 01, 2012, 12:14:25 am »
no, see.. my original texture is 320x240.

I want the sprite that is scaled 1x1 to be 320x240, and the sprite scaled widthXheight to be fullscreen.

This SHOULD have to do with the viewport. My best guess is that the RenderWindow doesn't update it's internally used viewport matrix when it's resized

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Graphics system and texture questions
« Reply #3 on: March 01, 2012, 04:41:42 am »
I think you are correct on your last assumption. You should try and process the window resize event to update its viewport if you want the resolution to change on resizing.

new_task

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Graphics system and texture questions
« Reply #4 on: May 25, 2012, 04:26:58 pm »
@ Lacrymology:

How did you convert the Kinect DepthData into a sf::image? Can you post the source code of the updateDepthBuffer() function?

 

anything