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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ActionBoy

Pages: [1] 2 3
1
Graphics / Re: RenderTexture and OpenGL example
« on: June 10, 2012, 10:51:08 pm »
Well I'm just trying to extend the OpenGL example with having it render the OpenGL specific stuff to a render texture to then be copied to the output window.

I can verify that the render texture have correct OpenGL states and that stuff are "rendered" to it. I randomize a clear color every frame and the render texture get that color. It is also copied to the window as I can see the effect. Removing the copy gives me a black screen with the example text. What doesn't work is the actual geometry. No cube is rendered to the render texture. I don't understand why? Am I missing something?

I know I have succeeded with this before but just this case where I am trying to only extend the OpenGL example I can't get it to work. What am I missing?


////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Deferred OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);
       
        sf::RenderTexture geometryBuffer;
        geometryBuffer.create(800, 600, true);
        sf::Sprite geometrySprite(geometryBuffer.getTexture());
       
        window.setActive();

    // Create a sprite for the background
    sf::Texture backgroundTexture;
    if (!backgroundTexture.loadFromFile("resources/background.jpg"))
        return EXIT_FAILURE;
    sf::Sprite background(backgroundTexture);

    // Load an OpenGL texture.
    // We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
    // but here we want more control on it (generate mipmaps, ...) so we create a new one from an image
    GLuint texture = 0;
    {
        sf::Image image;
        if (!image.loadFromFile("resources/texture.jpg"))
            return EXIT_FAILURE;
        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getWidth(), image.getHeight(), 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);
    }
       
        // window.setActive();
        geometryBuffer.setActive();

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glClearDepth(1.f);
        glClearColor(0.f, 0.f, 0.f, 0.f);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 800.f/600.f, 1.f, 100.f);

    // Bind our texture
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);
    glColor4f(1.f, 1.f, 1.f, 1.f);

    // Create a clock for measuring the time elapsed
    sf::Clock clock;

    // Start game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                window.close();

            // Escape key : exit
            if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                window.close();

            // Adjust the viewport when the window is resized
            if (event.type == sf::Event::Resized)
                        {
                                // window.setActive();
                                geometryBuffer.setActive();
                glViewport(0, 0, event.size.width, event.size.height);
                        }
        }

        // Draw the background
        window.pushGLStates();
        window.draw(background);
        window.popGLStates();

        // Activate the window before using OpenGL commands.
        // This is useless here because we have only one window which is
        // always the active one, but don't forget it if you use multiple windows
                // window.setActive();
        geometryBuffer.setActive();

        // Clear the depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Apply some transformations
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0, 0, -5.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
        glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);

        // Draw a cube
        float size = 1.f;
        glBegin(GL_QUADS);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, size);
            glTexCoord2f(1, 1); glVertex3f( size,  size, size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, size);

            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(-size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(-size, -size,  size);

            glTexCoord2f(0, 0); glVertex3f(size, -size, -size);
            glTexCoord2f(0, 1); glVertex3f(size,  size, -size);
            glTexCoord2f(1, 1); glVertex3f(size,  size,  size);
            glTexCoord2f(1, 0); glVertex3f(size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, -size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, -size,  size);

            glTexCoord2f(0, 1); glVertex3f(-size, size,  size);
            glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
            glTexCoord2f(1, 0); glVertex3f( size, size, -size);
            glTexCoord2f(1, 1); glVertex3f( size, size,  size);

        glEnd();
               
                geometryBuffer.display();

        // Draw some text on top of our OpenGL object
        window.pushGLStates();
                window.draw(geometrySprite);
        sf::Text text("SFML / OpenGL demo");
        text.setColor(sf::Color(255, 255, 255, 170));
        text.setPosition(250.f, 450.f);
        window.draw(text);
        window.popGLStates();

        // Finally, display the rendered frame on screen
        window.display();
               
                std::cout << sf::err();
    }

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

    return EXIT_SUCCESS;
}
 

Also you are aware of that the projection matrix aspect ratio is wrong?

Update: Remade the example and if I uncomment the activation of the window and comment the geometry buffer activation it works like I would expect it to do. (Though the clear hides the background but it is expected so not weird)

Second Update: Tried with rendering a test sprite to the render texture and it works just like it should so rendering to the texture works. Just not opengl geometry? But SFML uses that behind the scene so what is missing?

I can't get this to work. I switched:
Code: [Select]
       
// window.setActive();
 geometryBuffer.setActive();
to
Code: [Select]
       
 window.setActive();
// geometryBuffer.setActive();

But still no opengl geometri. What have I missed?

2
SFML projects / Linavalanche
« on: November 27, 2011, 12:06:17 pm »
Do you encrypt the data sent to the mysql?

3
General / Vector2f Help
« on: November 25, 2011, 07:14:48 am »

4
SFML projects / 30secGo - Released on indievania.
« on: November 23, 2011, 02:17:38 pm »
The game is fast paced, but less colors and animation then meatboy. Each level has a 30 sec time limit to encourage people with just a couple of minutes free time to play the game. Website should be up by the end of the day with a couple of minutes gameplay.

5
SFML projects / 30secGo - Released on indievania.
« on: November 22, 2011, 05:20:02 pm »
Just released 30secGo. A "hard platformer" I have been working on for awhile. Using SFML for everything.

The game is built around a "chip n dale"ish feel with precise controls. Right now has 54 levels and 16 achivements. Every level is handdrawn and then scanned and saved as png. Then with the ingame editor each level is tiled.

Not much more to say.

Gameplay:
http://www.verticalvertex.com/

Article over at DIYGamer:
http://www.diygamer.com/2011/11/30-seconds-complete-level-30secgo/




gameplay: http://www.verticalvertex.com/
projectpage: http://www.indiedb.com/games/30secgo/
store: http://beta.indievania.com/games/30secgo

6
General / SFML Complete Game Tutorial
« on: October 28, 2011, 08:58:34 pm »
A great tutorial. Wish I found something like this 10 years ago. Keep up the great work and good luck to everything you do.

7
SFML projects / [RELEASED] SFMLUploads.Org
« on: June 13, 2011, 08:00:42 pm »
Another great site in the works:D

8
SFML projects / SFSL - SFML File System Library
« on: June 13, 2011, 07:55:15 pm »
Sounds like a great project. Good luck.

9
SFML projects / Map generator (perlin noise)
« on: June 04, 2011, 09:43:20 am »
Looks great. Would fit perfect in a rouge game.

10
SFML projects / NESconv - Image to 8bits NES style
« on: April 25, 2011, 04:46:49 pm »
As a nes fan I must say it looks like a great project:D

11
SFML wiki / Get ip adress from php page.
« on: February 26, 2011, 05:59:05 pm »
Yes, but this is also a simple introduction on how to get a value from your own server.

12
SFML wiki / Get ip adress from php page.
« on: February 26, 2011, 05:35:27 pm »
This small code might help someone with a little php/sfml coding. Would it fit in the wiki?

main.cpp
Code: [Select]

#include <SFML/Network.hpp>
#include <iostream>

using namespace std;

sf::IPAddress mMyIP;

string mStringDomain    = "http://www.yourdomain.com";
string mStringURI       = "/ip.php";

int getMyIP()
{
    sf::Http Http;

    Http.SetHost(mStringDomain);

    // Prepare a request to retrieve the index page
    sf::Http::Request Request;
    Request.SetMethod(sf::Http::Request::Get);
    Request.SetURI(mStringURI);

    sf::Http::Response Page = Http.SendRequest(Request);

    if(Page.GetStatus()==200)
    {
        mMyIP = Page.GetBody();
        if(mMyIP.IsValid() == true)
        {
            cout<<"My IP: "<<mMyIP.ToString()<<endl;
            return 1;
        }
        else
        {
            cout<<"The ipadress retrieved was not valid."<<endl;
            return -1;
        }
    }
    else
    {
        cout<<"Could not connect."<<endl;
        return -2;
    }
}

int main()
{
    getMyIP();

    // Wait until the user presses 'enter' key
    std::cout << "Press enter to exit..." << std::endl;
    std::cin.ignore(10000, '\n');

    return EXIT_SUCCESS;
}


ip.php
Code: [Select]

<?php 
   
echo $_SERVER['REMOTE_ADDR'&#93;; 
?>


13
Graphics / Problem with sf::Font
« on: February 13, 2011, 09:51:09 am »
I have found it works better if you only sizes 4, 8, 12, 16, 32 and such.

14
SFML projects / Human Skeleton Animator
« on: February 08, 2011, 05:20:19 pm »
Make the walking animation a little more "realistic" and the whole project will look better. Keep up the great work.

15
Feature requests / Drawing textured shape?
« on: February 05, 2011, 03:41:54 pm »
Excellent.

Pages: [1] 2 3