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.


Topics - Groogy

Pages: 1 [2] 3 4 5
16
Graphics / RenderTexture and OpenGL example
« on: March 31, 2012, 04:37:07 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?

17
C / Faulty Cmake configuration I think
« on: February 10, 2012, 10:13:00 pm »
Well been trying to compile latest CSFML version several times. And it fails everytime with the same error which looks like if the cmake files are not in order. I tried cleaning out the cmake generated files and redownloading the library but nothing worked.

The same result for release as well.
Is it something on my end? Update cmake or something like that?


18
Feature requests / Format types for RenderTexture
« on: February 08, 2012, 01:11:18 am »
I am not entirely sure if this is possible. Looked at OpenGL documentation and in the source of SFML but couldn't really find it anywhere.

What I'm talking about is specifying the target texture format. Like for instance the format of a normal render texture is R8G8B8A8 unsigned normalized float(0-1 range). I think it should be that as well in OpenGL. And for a HDR texture it is R16G16B16A16 float(single precision range). And so on. There are about 20 different possible formats and they all have their unique uses and are both the only way to achieve some post processing effects to also being optimizations.

I don't feel it's out of range for SFML to implement it as fragment shading is becoming more and more used in 2D games. But since I couldn't find anything in SFML's source that actually set a format I have no idea if it is possible. But it would be very weird if you couldn't or I might just be blind or looking at something wrong. Or maybe OpenGL doesn't support it until OpenGL 3.0?

The interface wouldn't be that alien, would be much like how windows does with style I guess.

Code: [Select]

class RenderTexture
{
public:
    void Create( unsigned int aWidth, unsigned int aHeight, sf::Uint32 aFormat = sf::Format::Default, bool aCreateDepthFlag );
};


The only real difference for interface is handled in GLSL. The return value in the fragment shader is different but that's part of OpenGL and not SFML.

Use-cases for this feature would be(And yes I am thinking out of a 2D perspective):
  • High-Dynamic-Range colors
  • Shadow buffers
  • Glow effect(Not bloom but artist controlled glow)
  • GPU-based custom calculations(Like average luminance)
  • Fog of war(Could count to above)

Those are the uses that I personally have used this feature for and there might be things I have missed. Some of these can be calculated using the default texture format but then we have like HDR colors and glow effect that requires a more advanced format.

Edit: Actually found where it is done:
Code: [Select]
GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, myTextureWidth, myTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); So I guess for something like HDR texture it would be GL_RGBA16 and GL_FLOAT right instead?

19
Graphics / Flipped RenderTexture
« on: January 29, 2012, 04:41:38 am »
I am pretty sure we discussed this somewhere but I couldn't find it when searching for it.

Well anyway the resulting texture from a RenderTexture is flipped in the Y-coordinate. Right and I thought I could just do a flip of the sprite that I worked with.... but that functionality is long gone so how do I solve it? xD
Negative scaling is still not available right?

20
C / Safe Casting of types
« on: December 31, 2011, 01:45:02 am »
Yeah, I'm wondering if it's safe to to cast like between RenderWindow and Window in the C binding?

Can I more or less do something like:

Code: [Select]
sfRenderWindow *window = sfRenderWindow_Create(/*foobar*/);
sfWindow_Display( window );


You know where we have inheritance in C++. To use it similarly in C.

21
C / Miss-spells in Audio CSFML
« on: December 30, 2011, 12:31:07 am »
Well I'm just experimenting and testing around a little and when trying to compile CSFML it failed because it couldn't find some methods in the Audio module. And from what I can see it just looks like it is some misspelling.

Here's a list:
Code: [Select]
What it is -> What it should be
GetSamplesCount -> GetSampleCount
GetChannelsCount -> GetChannelCount


Also I'm guessing that this isn't updated to the latest SFML2 right? When will that come?

Okay, checked out an old version then the audio module functions weren't missspelled, nevermind, my bad for posting too soon.

22
SFML projects / Raiders of the Galactic North
« on: December 22, 2011, 06:29:40 pm »
Aight gonna show off my first 3D project I worked at together with Rimfrost Studios



I've already checked up with Laurent and It's okay that I post here, despite the fact that this actually got nothing to do with SFML. In fact it's developed using DX10 so you will need at least a DX10 compatible card and DX10 installed on your computer if you want to try it out.

The game is a 3D Space Shooter set in a setting where evil vikings raid your homeland and you have to defend it. It's a very small game and is only supposed to last for 30 min. It's a school project but we try to be as close to AAA games as possible with our work. It's very simple, very mainstream and should be easy to get into.

Reason for putting here is to ask for opinions, maybe people see something they think we should improve for the next game, what we might possibly done wrong and so on. But most importantly. We need a list of viable candidates for testing on our games. So if you are interested on that please let me know. We would really love opinions from other developers as we ourselves become blind to our mistakes as we become accustomed to them. Anything you got to say will be valuable to us. Especially if you would like to test our coming games. There will be three more projects before we are going away on internships(I'm aiming for Arkane Studios in France)

The game can be downloaded here: http://www.sendspace.com/file/d4xe0f
I might have to warn you that the voice acting is pretty horrible, it's just a student project so well I was the one doing the voices...  :twisted:
Everyone in my class wants to kill me know every time I does the Sarge's voice. You'll see ;)

Anyway for this project I worked as Tech Programmer, I was responsible for anything in the engine, I created the shader, lighting, HDR, Bloom, basically everything that made the game actually render. I was also assigned at the position as Code Lead and for a short duration as Art Lead as they didn't have anyone with enough experience so just to kick start everything.

Also if you got a question as of how things work, etc. I can do that for you, give you snippets or teach you how to do it or explain the fundamentals. But I am not allowed to release the entire source as it's property of the university The Game Assembly(This is so we don't start suing each other for ownership within the group, so it's for our own protection, the school is prohibited by Swedish law to profit on anything we do).

23
Graphics / Shaking sprites and shapes
« on: December 04, 2011, 12:10:33 am »
Youtube video of the problem: http://youtu.be/CdcDim0yR70
Though seems like the screen capture on my craptop is lagging a little so might be impossible to actually see the glitch.

I don't really know the source of the bug and I've tried a few things to see if it would affect but I couldn't narrow it down at all.

What happens is that when I move around everything shakes, at least if there is an interruption in the pattern it is noticeable. I figured it could have to do with that I both move the sprite and shape while I am also changing the sf::View of the render target. Though I removed so that I only moved sprites and shapes and not the view but I still had the "shakes".

Someone that looked over my shoulder while testing it on another graphics card thought it might be aliasing issues?

Just wondering if anyone has ideas?

Done with SFML2(not new graphics API) running on mobile Nvidia card and a really crappy laptop. Though the same result(though was long time ago) was viewable on a high-end machine.

24
General / Delayed creation of window on MinGW
« on: October 09, 2011, 10:08:41 pm »
I don't get what's the difference because I use MinGW for Ruby as well and I don't experience that there but when doing it using pure C++ I get a 20 second delay.

My Log:
Quote
[INFO]   2011-10-09 22:04:03 -- void GDE::Init() : Development system is initiat
ing...
[INFO]   2011-10-09 22:04:03 -- int main() : Starting application...
[INFO]   2011-10-09 22:04:24 -- int main() : Window created
[INFO]   2011-10-09 22:04:27 -- void GDE::OnExit() : Application exiting...

Process returned 0 (0x0)   execution time : 24.193 s
Press any key to continue.


And my code is:
Code: [Select]
#include <GDE/GDE.hpp>
#include <GDE/RuntimeDisplayer.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

int main()
{
    GDE::Init();
    GDE::GetLogger().SetLevel( GDE::Logger::DebugSeverity );
    GDE_INFO( "Starting application..." );
    sf::RenderWindow window;
    window.Create( sf::VideoMode( 800, 600 ), "Hello World!" );
    GDE_INFO( "Window created" );
    window.Show( true );
    sf::Clock clock;
    while( window.IsOpened() == true )
    {
        sf::Uint32 delta = clock.GetElapsedTime();
        clock.Reset();
        sf::Event event;
        while( window.PollEvent( event ) == true )
        {
            if( event.Type == sf::Event::Closed )
            {
                window.Close();
            }
        }

        window.Clear();
        GDE::RuntimeDisplayer::Update( delta );
        GDE::RuntimeDisplayer::Render( window );
        window.Display();
    }
    return 0;
}


Why am I experiencing such a huge delay before the Create function returns? And why don't I get a 20 second delay in rbSFML? Anyway it isn't really breaking but it makes debugging a lot slower as I have to wait before the application really kicks in.

UPDATE: Well after making it into a more complete application I get this log instead:
Quote
[INFO]   2011-10-09 23:10:00 -- void GDE::Init() : Development system is initiat
ing...
[INFO]   2011-10-09 23:10:00 -- void Game::Init() : Initiating application...
[INFO]   2011-10-09 23:10:22 -- void Game::Init() : Creating window...
[INFO]   2011-10-09 23:10:22 -- void Game::Init() : Everything done!
[INFO]   2011-10-09 23:10:24 -- void GDE::OnExit() : Application exiting...

Process returned 0 (0x0)   execution time : 23.902 s
Press any key to continue.


When initiating the application is when the window instance is actually allocated and then I call sf::Window::Create() later. As you see here I have the exact same 21 second delay here as before.

25
General / Slow math in Ruby
« on: October 08, 2011, 04:26:44 pm »
Keep in mind while reading that I'm doing this to challenge myself.

Alright while I wait for the new Graphics API comming out I'm faking perspective on the CPU with Ruby which is really really slow as it seems. My minimum platform are also pretty slow so it kinda backfires on me.

Here is what I am currently doing:


And the framerate of 600 FPS is what I've reached after micro optimizing the shit out of my perspective algorithm. And I'm out of ideas on what I can improve more. If I comment out the update on my tiles I will reach up to something about ~1300 FPS(I'm still looping trough them).

I want to see if someone else might find what I can improve in order to not have such a huge performance penalty? Maybe someone can break out parts in the math that's not needed or something I don't know. It's not really a language specific question.

Here's my perspective faking:
Code: [Select]
class Tile
  def update( camera_position )
    x_movement_factor = @position.z * ( camera_position.x.to_i - @position.x * Tile::Size ) / Tile::HalfSize
    y_movement_factor = @position.z * ( camera_position.y.to_i - @position.y * Tile::Size ) / Tile::HalfSize
    x_movement_factor = @max_movement_factor if x_movement_factor > @max_movement_factor
    x_movement_factor = @min_movement_factor if x_movement_factor < @min_movement_factor
    y_movement_factor = @max_movement_factor if y_movement_factor > @max_movement_factor
    y_movement_factor = @min_movement_factor if y_movement_factor < @min_movement_factor
    @sprite_origin.x = HalfSize + x_movement_factor
    @sprite_origin.y = HalfSize + y_movement_factor
    @sprite.origin = @sprite_origin
     
    x_scale_factor = 1.0
    y_scale_factor = 1.0
    if @max_movement_factor != 0
      depth_factor = 1 + @position.z * 0.25
      x_scale_factor = depth_factor + x_movement_factor.abs / @max_movement_factor.to_f
      y_scale_factor = depth_factor + y_movement_factor.abs / @max_movement_factor.to_f
    end
    @sprite_scale.x = x_scale_factor
    @sprite_scale.y = y_scale_factor
    @sprite.scale = @sprite_scale
  end
end


Of course when the support for Vertex Shaders come this won't be a problem but would still be nice to have some ideas on how to maybe optimize other areas in Ruby more.
Any ideas you have can come in handy. Any idea you have that can make math calculations in Ruby faster is a plus.

26
Graphics / Faking perspective in SFML without vertex shaders
« on: October 02, 2011, 06:29:42 pm »
Aight hello! Has been waiting for the new graphics API for some time but decided I wanted to continue working but I eventually hit the deadspot I've been fearing. I want to fake the perspective without actually doing 3D. I first thought I should modify SFML to support taking in 3D coordinates and do real 3D with opengl but I thought a little and faking it is actually quite interesting and might give some nice retro-feeling. (It's not a 100% off the table, I'm doing it in Ruby so might need the extra performance I would get from real 3D rendering)

Anyway so far I've been faking it by moving the different levels to achieve a depth feeling which is very easily achievable by moving sprites around a little. But I hit the deadspot when I come to walls.

North perspective:



North west perspective:



The problem comes as you see when we reach a corner perspective where two directions meet. Faking it in one direction is easy but two at the same time means that I need to distort the rendering somehow and I have no idea as of how to do it with the current state of SFML2 or if it is even possible?

My question: Will I have to wait for the new graphics API to resolve this and do it with vertex shaders or is there some way to achieve this on the CPU for the time being so I can continue developing the walls?

Aight and remember I'm doing this with rbSFML so just saying "Well modify SFML source yourself" is not as trivial as it sounds.

27
Feature requests / Shader Architecture for 3D in SFML
« on: September 01, 2011, 02:53:41 pm »
Yo! This might more be of a brainstorming/discussion than an actual feature request.

As some might know there is an upcoming huge change to the Graphics module where it will include Vertex Shader capability to SFML.

If using a Vertex Shader it would for us be possible to create 3D graphics in SFML without actually concerning ourselves with any OpenGL stuff at all more than the language GLSL. the main requirements would be a vertex shader that looks something like this I guess:
Code: [Select]

uniform mat4 toWorldSpace;
uniform mat4 toViewSpace;
uniform mat4 projection;
 
// I know OpenGL has ModelView matrix instead of separating
// it into two seperate but I'm writing with what I am comfortable with.

void main() {
    vec4 vertex = gl_Vertex
    vertex *= toWorldSpace;
    vertex *= toViewspace;
    vertex *= projection
    gl_Position = vertex;
}


Have never used GLSL so somethings might be wrong but the math should be the same as my software renderer and as in HLSL.

Though this requires us to be able to pass 3D vertexes to OpenGL to use it which SFML at the moment don't support and I don't expect it to either since it's a 2D library.

Also from what I know using a Shader makes most of the states in OpenGL unused unless you use it in your own Shader. So from my point of view and the knowledge I got of OpenGL is that it would make it possible for us to generate 3D graphics with SFML, no custom OpenGL calls and no need of maintaining the state machine right?

My feature request is that somehow be able to pass on 3D vertexes to OpenGL trough SFML. Maybe by defining a custom drawable and have the sf::Renderer extended to take in 3D coordinates instead of only 2D for placing a vertex? This request is not related with: http://www.sfml-dev.org/forum/viewtopic.php?t=5729 What I want is the possibility to create 3D graphics using only SFML, no custom OpenGL and no change in how the drawing interface works now or will work after the change.

Note even if Laurent decides no he don't want this, I still won't give up I'll try and hack something together as an extension that will first be available for rbSFML and then C++ :twisted: One of the reasons I want this is because I have trouble getting ruby-opengl installed on my Windows machine and this would make things SO much simpler.

Anyone else that might have more experience with 3D and OpenGL/Shaders than me that might be able to give more detailed information?

28
SFML wiki / Groogy's Development Environment
« on: August 24, 2011, 07:19:48 pm »
Hi! Got a little addition to the Wiki. I've placed it under projects but it is not a project of it's own. It's an "environment" for use when developing applications with rbSFML making it much more easier.



The main feature is that it allows the developer to code while the application is running and the environment will adapt to the new code changes that has been made. So let's say we are sitting and moving a small sprite around a few pixels left and right trying to find the perfect place, this will let us do the change all in one go without having to restart the application.

I'm very open from other ruby users anything they would feel that could help their development. An idea is that I might eventually add a console window where you can attach watches easily to see the values of variables be changed at real time.

Example of it all in action:
[/img]

Youtube video: http://www.youtube.com/user/sirvogelius?feature=mhee

29
General / Look At implementation
« on: July 11, 2011, 10:36:00 pm »
Alright per request for my engine I am going to implement a LookAt function for the camera. I can do it to a matrix but the problem that arises is that my rotation vector will be wrong, it won't get the new values from the LookAt operation.

Is there anyone here that knows how to do a LookAt with just a rotation vector?

Here's my code so far:
Code: [Select]
void GGE::Interface::Camera::LookAt( const Vector3f aCenter, const Vector3f aUp )
{
Vector3f forward = (aCenter - myPosition).Normalize();
Vector3f side = forward.Cross( aUp.Normalize() );
Vector3f up = side.Cross( forward );
SetRotation( /* This is what I don't know? */ );
}


I can apply those 3 vectors to a matrix but like I said then GetRotation won't return the right rotation. So how do I combine these to one rotation vector? I thought I was close when I multiplied them together, but that always resulted in a zero vector.

I am no math brain, so I am having a really hard time figuring this by myself. Any pointers would be nice.

30
Window / Polling events and setting cursor position thread safety
« on: July 08, 2011, 09:32:03 am »
Oi!

I'm just wondering if it is thread safe to pull events in one thread and set the cursor position in another thread? This is in SFML2 of course.

Because of the recent changes it feels like they are being detached more and more from each other so I suspect they got nothing to do with each other but just want to make sure before I change anything in my engine.

Pages: 1 [2] 3 4 5