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

Author Topic: Buffers?  (Read 7463 times)

0 Members and 1 Guest are viewing this topic.

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Buffers?
« on: July 11, 2012, 03:28:54 pm »
So I've been working with the SFML Graphics package for close to 6 months now, and from what I've noticed there is no way to actually create and draw an actual buffer. The RenderWindow has a built in buffer that you can draw to, and then the RenderWindow prints the built-in buffer to the screen. I'm assuming I would have to delve into the OpenGL side of things for this, which I am completely clueless in.

The problem being...  I am trying to make a game with a randomly generated dungeon. As doing such... I need very large floors with a TON of tiles placed dynamically. Some need to be normal, others cracked, and others mossy all scattered about at random intervals. And this system works fine all up until I create a room with a sizable floor... The thing will drop from roughly 60FPS (using the framerate limit and verticalsnyc, the game runs at roughly 4000FPS without the flooring or the limitations) to about 10FPS. And maybe it's just a hunch... I'm thinking it has to do with the massive amounts of tiles needing to be rendered in a single frame. So I was thinking we can draw all these tiles to a buffer upon startup, and then keep rendering the buffer rather than each individual tile.

So like I said I am very clueless about OpenGL, so if someone could tell me how this whole buffer thing could be done / at least point me in the right direction... That would be very kind of you.
Thanks
++Zaid

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Buffers?
« Reply #1 on: July 11, 2012, 03:57:06 pm »
If you use SFML 2.0, which you should (!!), there's the sf::RenderTexture which is a off-screen buffer/texture. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Buffers?
« Reply #2 on: July 11, 2012, 04:14:36 pm »
For this I'd rather go with sf::VertexArray. sf::RenderTexture is limited by the maximum size of texture supported by the graphics card, and the result cannot be easily edited after it is created.
Laurent Gomila - SFML developer

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Buffers?
« Reply #3 on: July 11, 2012, 04:16:53 pm »
Is there anyway I can do any of these things inside of SFML 1.6?
Learning all the new concepts in SFML 2.0 without a really complete tutorial on the thing seems pretty daunting. Is there no way I can Implement these features of 2.0 into 1.6?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Buffers?
« Reply #4 on: July 11, 2012, 04:23:26 pm »
No, unless you use OpenGL directly.

There's no tutorial yet, but you can read the online API doc and the forum (and then ask more questions of course). There's nothing complicated:
- sf::RenderTexture has the same API as sf::RenderWindow, the only difference is that it draws to a texture
- sf::VertexArray is just like an array of sprites, except that the definition of the quads and their texture coordinates is more low-level
Laurent Gomila - SFML developer

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Buffers?
« Reply #5 on: July 11, 2012, 04:50:28 pm »
No, unless you use OpenGL directly.

There's no tutorial yet, but you can read the online API doc and the forum (and then ask more questions of course). There's nothing complicated:
- sf::RenderTexture has the same API as sf::RenderWindow, the only difference is that it draws to a texture
- sf::VertexArray is just like an array of sprites, except that the definition of the quads and their texture coordinates is more low-level

Well I guess I really should update...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Buffers?
« Reply #6 on: July 11, 2012, 05:02:51 pm »
For this I'd rather go with sf::VertexArray. sf::RenderTexture is limited by the maximum size of texture supported by the graphics card, and the result cannot be easily edited after it is created.
The texture size is a limit which should be worked around (not letting it grow to unreasonable sizes) but the question is rather, will the tiles have to change?
If not then drawing hundrets of vertices with their own textures (or sprite sheet) seems to me kind of extrem if you could just draw a few textures instead.
But then again GPUs are build to draw not only hundrets but thousands of vertices and you get a way more flexible system with a vertex array. :D

Is there no way I can Implement these features of 2.0 into 1.6?
Implementing those features would set you way further back, than just switch to SFML 2 and investing some good time into your future. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Buffers?
« Reply #7 on: July 11, 2012, 05:16:31 pm »
For this I'd rather go with sf::VertexArray. sf::RenderTexture is limited by the maximum size of texture supported by the graphics card, and the result cannot be easily edited after it is created.
The texture size is a limit which should be worked around (not letting it grow to unreasonable sizes) but the question is rather, will the tiles have to change?
If not then drawing hundrets of vertices with their own textures (or sprite sheet) seems to me kind of extrem if you could just draw a few textures instead.
But then again GPUs are build to draw not only hundrets but thousands of vertices and you get a way more flexible system with a vertex array. :D

Is there no way I can Implement these features of 2.0 into 1.6?
Implementing those features would set you way further back, than just switch to SFML 2 and investing some good time into your future. ;)

Tiles will NOT change once the floor has been set down, And I just installed SFML 2 and am toying around with it now. I'm not seeing any sort of sf::RenderTexture, or sf::VertexArray :/

EDIT: Found .hpp but it's not a class type or whatever? I don't know.
« Last Edit: July 11, 2012, 05:19:01 pm by Zaid »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Buffers?
« Reply #8 on: July 11, 2012, 05:29:12 pm »
Tiles will NOT change once the floor has been set down, And I just installed SFML 2 and am toying around with it now. I'm not seeing any sort of sf::RenderTexture, or sf::VertexArray :/

EDIT: Found .hpp but it's not a class type or whatever? I don't know.

RTFM: sf::RenderTexture & sf::VextexArray

If you can't work with them in your project, then you're still using the old heards/libraries, change the settings in the project/make file.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Buffers?
« Reply #9 on: July 11, 2012, 05:32:57 pm »
Tiles will NOT change once the floor has been set down, And I just installed SFML 2 and am toying around with it now. I'm not seeing any sort of sf::RenderTexture, or sf::VertexArray :/

EDIT: Found .hpp but it's not a class type or whatever? I don't know.

RTFM: sf::RenderTexture & sf::VextexArray

If you can't work with them in your project, then you're still using the old heards/libraries, change the settings in the project/make file.

I don't think that's so... I've dumped all the header and libraries into an SFML2 folder inside of the lib and include folders in VC. And I'm calling out all the headers specifically from SFML2/x.hpp, and same with the libraries.

#include <SFML2/Graphics.hpp>
#include <SFML2/Graphics/RenderTexture.hpp>
#include <iostream>
#include <string>

#ifdef _DEBUG
#pragma comment (lib, "SFML2/sfml-system-s-d.lib")
#pragma comment (lib, "SFML2/sfml-window-s-d.lib")
#pragma comment (lib, "SFML2/sfml-graphics-s-d.lib")
#else
#pragma comment (lib, "SFML2/sfml-system-s.lib")
#pragma comment (lib, "SFML2/sfml-window-s.lib")
#pragma comment (lib, "SFML2/sfml-graphics-s.lib")
#endif

int main()
{
   sf::RenderTexture shit;
   return 0;
}


There's nothing in project properties that has anything to do with SFML as far as I know.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Buffers?
« Reply #10 on: July 11, 2012, 05:49:45 pm »
Eeeekk :o

Ever read the tutorial on SFML and Visual Studio (for SFML 1.6) or SFML and Visual C++ (for SFML 2.0)? ::)
What you're doing isn't imho a solution that one should even consider using, so I certaintly won't get into helping you figure out what went wrong with your setup...
Also I hope you've removed the old SFML 1.6 files before copying everything into that folder...

And FYI there's a code=cpp tag that will highlight your code, or even better there's a dropdown menu that lets you just with two clicks select that code tag. ::)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Buffers?
« Reply #11 on: July 11, 2012, 06:32:08 pm »
Zaid, do you have a compile error? You're talking about headers etc. but... what's wrong? Please describe the problem first ;)

Quote
If not then drawing hundrets of vertices with their own textures (or sprite sheet) seems to me kind of extrem if you could just draw a few textures instead.
This kind of solution implies that all the tiles are in a single texture. If they are all in separate textures, this solution is ruined.
The amount of primitives is still negligible for the GPU, remember that they talk in millions of triangles per second.
Laurent Gomila - SFML developer

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Buffers?
« Reply #12 on: July 12, 2012, 04:50:31 am »
Alright guys / gals. So I've updated to SFML 2.0. I have the libraries statically linked using pragma comments, the project properties set to use static linking rather than .dll's and everything installed how it's supposed to be. And I am coming across some errors.

Here is the code:
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/RenderTexture.hpp>
#include <iostream>
#include <string>

#ifdef _DEBUG
#pragma comment (lib, "sfml-system-s-d.lib")
#pragma comment (lib, "sfml-window-s-d.lib")
#pragma comment (lib, "sfml-graphics-s-d.lib")
#else
#pragma comment (lib, "sfml-system-s.lib")
#pragma comment (lib, "sfml-window-s.lib")
#pragma comment (lib, "sfml-graphics-s.lib")
#endif

int main()
{
   sf::RenderWindow App(sf::VideoMode(600, 400, 32), "Cyrus");
   App.setVerticalSyncEnabled(true);
   App.setFramerateLimit(100);

   sf::RenderTexture shit;
   shit.setSmooth(false);
   sf::Event Event;
   
   sf::Texture Image;
   sf::Sprite Sprite;
   Image.loadFromFile("ruth_base.PNG");
   Image.setSmooth(false);
   Sprite.setTexture(Image);

   while(App.isOpen())
   {
      while(App.pollEvent(Event)){
         if (Event.type == sf::Event::Closed)
            App.close();
         if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
            App.close();
      }

      shit.clear();
      App.clear();

      shit.draw(Sprite);
      shit.display();
      App.display();
   }
   return 0;
}


And here are the errors:
1>------ Build started: Project: Aperture-Labrotories, Configuration: Debug Win32 ------
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderTexture::~RenderTexture(void)" (__imp_??1RenderTexture@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Texture::~Texture(void)" (__imp_??1Texture@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Sprite::~Sprite(void)" (__imp_??1Sprite@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::display(void)" (__imp_?display@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTexture::display(void)" (__imp_?display@RenderTexture@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (__imp_?draw@RenderTarget@sf@@QAEXABVDrawable@2@ABVRenderStates@2@@Z) referenced in function _main
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2V12@B)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::close(void)" (__imp_?close@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QBE_NXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Sprite::setTexture(class sf::Texture const &,bool)" (__imp_?setTexture@Sprite@sf@@QAEXABVTexture@2@_N@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Texture::setSmooth(bool)" (__imp_?setSmooth@Texture@sf@@QAEX_N@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Texture::loadFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class sf::Rect<int> const &)" (__imp_?loadFromFile@Texture@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$Rect@H@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Sprite::Sprite(void)" (__imp_??0Sprite@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Texture::Texture(void)" (__imp_??0Texture@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTexture::setSmooth(bool)" (__imp_?setSmooth@RenderTexture@sf@@QAEX_N@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderTexture::RenderTexture(void)" (__imp_??0RenderTexture@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::setFramerateLimit(unsigned int)" (__imp_?setFramerateLimit@Window@sf@@QAEXI@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::setVerticalSyncEnabled(bool)" (__imp_?setVerticalSyncEnabled@Window@sf@@QAEX_N@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IABUContextSettings@1@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>S:\Users\Logan\documents\visual studio 2010\Projects\Aperture-Labrotories\Debug\Aperture-Labrotories.exe : fatal error LNK1120: 24 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I've asked a couple friends and no one seems to have an answer for me. Any thoughts?
Also if someone could give me the lowdown on how to draw RenderTextures to a RenderWindow, that would be amazing. Since obviously RenderTextures aren't drawables. :I

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Buffers?
« Reply #13 on: July 12, 2012, 05:03:03 am »
There still is a code=cpp tag, so please make use of it!!

You have to #define SFML_STATIC.

Obviously you can't draw a sf::RenderTexture directly to a window, because those two are kind of the same, just that the window gets show on the screen where as the rendertexture will stay on the GPU memory.
But since it's a buffer/texture, you can easily just get the reference to the texture by calling getTexture(). Then just apply it to a sprite and draw it to the render window.

Also I'm curious why do you use pragma comment instead of normal project settings like everybody else is doing?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Buffers?
« Reply #14 on: July 12, 2012, 08:09:18 am »
Quote
Also if someone could give me the lowdown on how to draw RenderTextures to a RenderWindow, that would be amazing. Since obviously RenderTextures aren't drawables. :I
The online doc shows a working example.
Laurent Gomila - SFML developer