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

Author Topic: RenderTexture Issues.  (Read 8165 times)

0 Members and 1 Guest are viewing this topic.

Ezekiel

  • Newbie
  • *
  • Posts: 23
    • View Profile
RenderTexture Issues.
« on: August 12, 2013, 01:09:42 am »
I have issues with the RenderTexture.  I demonstrated what I want to see using directly rendering to RenderWindow.  See screen-shot Test.gif.  Note: this image was used to identify display locations,
(I attached the gifs, but it doesn't show me under 'Preview'.  If it does not show after posted, I will require instructions displaying screenshots on the forum)



For Test2, (that's what I was originally trying) the bottom line of pixels was smeered to the top, see Test2 screenshot...



I was trying different things to see if I could make it work, the 'setRepeated(true);' made it draw, however, with an error in y position.  See Test3...



The Code is below, Test1 is current config, 3 sections have notes for commenting and un-commanting code sections to set the test2 and test3...

#include <sfml.h>//incudeds all sfml libs, and set sfml libs as static link
#include <stdio.h>
#include <math.h>

sf::Color colorAdjust(sf::Color col, double adjust, bool alpha = false);


void main(void)
{
        sf::Clock clock;
       
        sf::RenderWindow App(sf::VideoMode(400, 300, 32), "Balls Window");


        float width = (float)App.getSize().x;
        float heigth = (float)App.getSize().y;
       
        //colors
        sf::Color brown(128, 96, 64);
        sf::Color box_band(colorAdjust(brown, 0.6));

        //circle1
        sf::CircleShape circle1;
        circle1.setRadius(75.0f);

        circle1.setFillColor(brown);
        circle1.setOutlineColor(box_band);
        circle1.setOutlineThickness(5.5f);
        circle1.move(0, 200);
       
        //circle2
        sf::CircleShape circle2;
        circle2.setRadius(75.0f);

        circle2.setFillColor(brown);
        circle2.setOutlineColor(box_band);
        circle2.setOutlineThickness(5.5f);
        circle2.move(300, -50);

        //info string
        sf::Font font;
        font.loadFromFile("arial.ttf");
       
        sf::Text info("Info______________________________________________________________", font);
        info.rotate(-4.0f);
        info.move(0, 278);
       
        //RenderTexture box
        sf::RenderTexture box;
        //********un-commented for test 3****************
        //box.setRepeated(true);
        //***********************************************
       
        box.create(width, heigth);
        box.clear(sf::Color(128,128,128));//to see where RenderTexture
        box.draw(circle1);
        box.draw(circle2);
        box.draw(info);
        box.display();
               
       

        sf::Sprite box_sprite;
        box_sprite.setTextureRect(sf::IntRect(0,0,width,heigth));
        box_sprite.setTexture(box.getTexture());

        while(App.isOpen())
        {
                sf::Event Event;
                while(App.pollEvent(Event))
                {
                        if(Event.type == sf::Event::Closed
                        || (Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
                        {      
                                App.close();
                        }
                }
                App.clear();
               
                //********un-commented for test 2 & 3************
                //shapes and string -> RenderTexture -> Sprite -> RenderWindow
                //App.draw(box_sprite);//texture through sprite
                //***********************************************

                //********un-commented for test 1****************
                //shapes and string -> RenderWindow
                App.draw(circle1);//rectange direct
                App.draw(circle2);//rectange direct
                App.draw(info);
                //***********************************************
               
                App.display();

                while(sf::seconds(0.100f) > clock.getElapsedTime());
                clock.restart();
               
        }


}

sf::Color colorAdjust(sf::Color col, double adjust, bool alpha)
{
        int r,g,b,a;
        r = (int)((double)col.r * adjust);
        if(r > 255) r = 255;
        g = (int)((double)col.g * adjust);
        if(g > 255) g = 255;
        b = (int)((double)col.b * adjust);
        if(b > 255) b = 255;
        a = (int)((double)col.a * adjust);
        if(a > 255) a = 255;
        if(!alpha)a = col.a;//return original value, if alpha is true
        return sf::Color(r,g,b,a);

}

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: RenderTexture Issues.
« Reply #1 on: August 12, 2013, 01:23:24 am »
Tried that code on my machine and Test 2 seems perfectly fine to me:



However, since I didn't have the "sfml.h" thing you have, I used "#include <SFML/Graphics.hpp>" instead, and I was dynamic linking for this test.

By the way, if you want to put images inside your post instead of just as attachments, you have to upload them to the internet somewhere so you refer to them by a url.  I like to use Gyazo to partially automate that process.

Edit: Tried it with static linking, same result.  I have no idea why it isn't working for you.  I'm using Visual C++ 2010 Express if it matters.

By the way, since I don't recall seeing that <sfml.h> header anywhere in the tutorials (or anywhere at all really), where'd you get it from?  Maybe that has something to do with this.
« Last Edit: August 12, 2013, 01:37:33 am by Ixrec »

Ezekiel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: RenderTexture Issues.
« Reply #2 on: August 12, 2013, 01:51:30 am »
Ixrec, what you are displaying is exactly what I was expecting to display on my computer.  You could add a font for that to work (no more default font).  Here is what I have for my sfml.h...

//by Disch, posted Here: http://www.cplusplus.com/forum/beginner/78091/#msg420663
#pragma once
#ifndef SFMLFULL_INCLUDED
#define SFMLFULL_INCLUDED

//comment out the following 3 lines to dynamicaly link
#ifndef SFML_STATIC
#define SFML_STATIC
#endif

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#if defined(_DEBUG) || defined(DEBUG)
    #if defined(SFML_STATIC)
        #pragma comment(lib,"sfml-graphics-s-d.lib")
        #pragma comment(lib,"sfml-audio-s-d.lib")
        #pragma comment(lib,"sfml-network-s-d.lib")
        #pragma comment(lib,"sfml-window-s-d.lib")
        #pragma comment(lib,"sfml-system-s-d.lib")
        #pragma comment(lib,"sfml-main-d.lib")
    #else
        #pragma comment(lib,"sfml-graphics-d.lib")
        #pragma comment(lib,"sfml-audio-d.lib")
        #pragma comment(lib,"sfml-network-d.lib")
        #pragma comment(lib,"sfml-window-d.lib")
        #pragma comment(lib,"sfml-system-d.lib")
        #pragma comment(lib,"sfml-main-d.lib")
    #endif
#else
    #if defined(SFML_STATIC)
        #pragma comment(lib,"sfml-graphics-s.lib")
        #pragma comment(lib,"sfml-audio-s.lib")
        #pragma comment(lib,"sfml-network-s.lib")
        #pragma comment(lib,"sfml-window-s.lib")
        #pragma comment(lib,"sfml-system-s.lib")
        #pragma comment(lib,"sfml-main.lib")
    #else
        #pragma comment(lib,"sfml-graphics.lib")
        #pragma comment(lib,"sfml-audio.lib")
        #pragma comment(lib,"sfml-network.lib")
        #pragma comment(lib,"sfml-window.lib")
        #pragma comment(lib,"sfml-system.lib")
        #pragma comment(lib,"sfml-main.lib")
    #endif
#endif

#endif // SFMLFULL_INCLUDED

The file resides in the 'SFML-2.1\include' folder.
I'm using WindowsXP 32bit version, and that limits me to VisualC++ 2008 Express.

I used the sfml.h file originally for 1.6, it may be missing new features for 2.1, causing the issues I'm experiencing.
« Last Edit: August 12, 2013, 01:58:50 am by Ezekiel »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: RenderTexture Issues.
« Reply #3 on: August 12, 2013, 01:58:34 am »
I think you should try following the SFML official visual studio setup tutorial and see if doing it that way fixes your problem somehow.  Nothing like this header is in any of the official tutorials so it may be some outdated trickery that made sense back in 1.6 or under some other unusual circumstances.  In any event, I did it the official way and the code's working for me.

Also, wow, what a weird place to see Disch's name pop up.  I use his utf8 to wstring function in my own program.

Ezekiel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: RenderTexture Issues.
« Reply #4 on: August 12, 2013, 03:31:45 am »
I have followed the tutorial using #include <SFML/Graphics.hpp> rather than the #include <sfml.h>, and the issues I have still exist.  I have tried the static or the non-static, and both create the same problem.  Any other possibilities that could solve the issues?  Since my code works fine for other people, it may be OS, hardware/driver, or compilation.  Is there a sfml recompile required using WindowsXP 32bit, or perhaps my video card ATI Radeon X1950 series may be the culprit, although the issue happens when the work is not going directly to the monitor, it's off screen.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: RenderTexture Issues.
« Reply #5 on: August 12, 2013, 12:35:37 pm »
The issue you are seeing comes your your graphics card, it has nothing to do with how you have SFML setup. Try updating your graphics card drivers and then let us know how that went.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Ezekiel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: RenderTexture Issues.
« Reply #6 on: August 13, 2013, 03:36:56 am »
That's what I did before posting the question on the forum.

I updated ATI Catalyst 10-2 (or older, I have archives if all versions I used) to AMD Catalyst 13-4, however, on the hardware Device Manager, the Radeon X1950 Series Driver Version was 8.512.0.0,  7/2/2008, the same as before I updated yesterday.  I will check if my install is actually updating the Radeon X1950 Series Driver to he latest.

My other plan is to try my exe file on my work computer to see if it runs on a different computer.  This may verify my hardware is causing the problem.

I will report my finding.

Ezekiel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: RenderTexture Issues.
« Reply #7 on: August 13, 2013, 09:01:15 am »
Interesting, see the attached image, I found this is what happens when I disable the Hardware Acceleration.

I found that with the driver provided with Catalyst 13-4, did not seem like it was updated.  Then I removed all their software (very difficult) and re-installed Catalyst 13-4.  Interesting, now it provided no ATI drivers, just the generic VGA driver from Windows XP, and without proper driver, my app provided the same image I just attached.  I guess AMD software doesn't properly install ATI Drivers to the XP32bit era computers.

I removed that poor quality software, which did nothing, and installed the second best up-to-date software, Catalyst 10.2.  It turns out that one provides a newer driver, Driver Version 8.593.100.0, 2/10/2010.  From what I recall, it's the same driver in Catalyst 13.4 for the Radeon X1950 series, only it actually installs the driver.

Previously, I have had to install a previous version for different reasons, such the last hour I spent getting my graphics card to connect properly to my TV, which is probably why I had an older version installed.  The good news, my program actually displays properly!!!  Now I can spend time on the actually stuff I wanted to do on my program.

Thanks All.

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: RenderTexture Issues.
« Reply #8 on: August 14, 2013, 11:12:50 am »
Don't use Render Targets with SFML, we already did SFML - Direct3D port to continue developing.  :P

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: RenderTexture Issues.
« Reply #9 on: August 14, 2013, 05:47:47 pm »
Don't use Render Targets with SFML, we already did SFML - Direct3D port to continue developing.  :P
Can somebody translate this to English or something? I don't get it...  :-\
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: RenderTexture Issues.
« Reply #10 on: August 14, 2013, 07:58:38 pm »
 :(

Ezekiel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: RenderTexture Issues.
« Reply #11 on: August 16, 2013, 01:53:46 pm »
I did some more testing.  After updating Radeon driver, Test2 works, however, Test3 now does something else wrong for the graphics, plus it now takes about 40 seconds for each frame.  Keep in mind, the RenderTexture rendering is not in the loop, the rendering is done before, and the loop just draws the sprite holding the RenderTesture. 

Fortunately I was just testing, I'm using as shown in Test2, however, it may make it impossible for me to generate repeated textures using my computer.

The actual reason I use the RenderTexture is because I am generating all my graphics with the computer, rendering Shapes, Text, and define Shapes.  My plan was to generate complex Images, rendering in the start-up, then Sprite the Images in the loop, much faster. 

My first attempt was to make a RenderImage class, based on RenderTarget, and Image, using SFML 1.6, (because SFML 2.0 was no released yet).  The RenderTarget class claims "Base class for all render targets (window, image, ...) More...", however, the RenderWindow was the only one, not the Image referred to.  Making a derived class did not work for me.  Then I heard the new version takes the rendering off the screen, that when I gave up on the RenderImage on SFML1.6 and that about when you heard from what happened.

If someone can help me with the RenderImage class, here is the code I made.  It ran like a normal Image, but I couldn't make it render anything.  Understanding the depth required to make it work is beyond my skill.  It's SFML 1.6 version, however, I agree it's best to use the newest, it may need modification.

Warning: I added a few things mostly unnecessary to make it work, it didn't.

header...
#pragma once

#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/RenderTarget.hpp>

namespace sf
{

//incomplete types, declared to be used for creating pointers to classes defined elsewhere.
class Drawable;
//class RenderWindow;


class RenderImage :
        public Image,
        public RenderTarget
{
public:
        RenderImage(void);//default
        RenderImage(const RenderImage& Copy);//copy
        RenderImage(const Image& Copy);//copy from normal image
        RenderImage(unsigned int Width, unsigned int Height, const Color& Col = Color(0, 0, 0, 255));//create blank image
        RenderImage(unsigned int Width, unsigned int Height, const Uint8* Data);//create using pixel data
        ~RenderImage(void);
    bool Create(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255));
        unsigned int GetWidth() const;
        unsigned int GetHeight() const;
private:
        virtual void OnCreate();
        virtual bool Activate(bool Active);

};

}//namesapce sf

cpp file...
#include "RenderImage.h"
namespace sf
{
//default
RenderImage::RenderImage(void)
{
        //Image();
        Initialize();
}
//copy
RenderImage::RenderImage(const RenderImage& Copy):
Image(Copy)
{
        Initialize();
}
//copy from normal image
RenderImage::RenderImage(const Image& Copy):
Image(Copy)
{
        Initialize();
}

//create blank image
RenderImage::RenderImage(unsigned int Width, unsigned int Height, const Color& Col):
Image(Width, Height, Col)
{
        //Image(Width, Height, Col);
        //Create(Width, Height, Col);
        Initialize();
}
//create image from pixel data
RenderImage::RenderImage(unsigned int Width, unsigned int Height, const Uint8* Data):
Image(Width, Height, Data)
{
        Initialize();
}

RenderImage::~RenderImage(void)
{
        //~Image();
}
bool RenderImage::Create(unsigned int Width, unsigned int Height, Color Col)
{
        bool Im_bool = Image::Create(Width, Height, Col);
        Initialize();
        return Im_bool;
}
bool RenderImage::Activate(bool Active)
{
    // For performances and consistency reasons, we only handle activation
    if (Active)
        //return SetActive();
                return true;//image does not have a window.SetActive(), no window!
    else
        return true;
}


//bool setActive(bool Active)
//{
//      return
//}

unsigned int RenderImage::GetWidth() const
{
        //return RenderTarget::GetWidth();
        return Image::GetWidth();
}
unsigned int RenderImage::GetHeight() const
{
        //return RenderTarget::GetHeight();
        return Image::GetHeight();
}


void RenderImage::OnCreate()
{
    // We can now initialize the render target part
    RenderTarget::Initialize();
}

}//namesapce sf

 

I hope someone can help.
If important, this may need a different thread.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Issues.
« Reply #12 on: August 16, 2013, 02:40:04 pm »
I haven't followed this thread from the start, and it seems like many things have changed, so you should summarize what's not working with sf::RenderTexture and provide a clearer code, now that only one test fails.

Also, this RenderImage class won't lead you anywhere, you need an implementation using OpenGL functions. Just putting some classes together won't make it magically work, the feature doesn't exist at all in SFML 1.6 ;)
Laurent Gomila - SFML developer

Ezekiel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: RenderTexture Issues.
« Reply #13 on: August 22, 2013, 03:55:58 am »
Laurent, summarization...

I was having with the RenderTexture, it wouldn't display properly.  Test1.gif shows what I expected (directly onto RenderWindow).  Test2.gif shows the smeared result using RenderTesture.  Test3 shows another thing I tried using setRepeated, witch showed stuff, but it wasn't accurately positioned, however, that wasn't what I wanted to used.

It turned out that my Radeon X1950 driver caused the issue.  Installing the newest driver made it work!  However, using the setRepeaded(true) with the newest driver is now Worse!  It takes 40 seconds to render each frame, and distorts the window differently.  I'm not using the setRepeated in this project (it was a test), however it may be impossible to use that function with the hardware I currently have.

The RenderImage, the document implied that it was available in SFML1.6,  "Base class for all render targets (window, image, ...) More...", kind of like RenderTesture in SFML2.1, "Base class for all render targets (window, texture, ...) More...".  You are correct, drawing to RenderTarget and adding an Image is beyond the Event-Horizon of OpenGL, it's beyond my skill.  That's how I got to the latest SFML API.  If you can add a RenderImage to SFML2.1, that would help if need to try to make one of those in the future. ;)

I appreciate the API you provide.  Every time I attempt to try something simple, I have to learn the most advanced, and you provide extensive code I can read and learn.

Thank you.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Issues.
« Reply #14 on: August 22, 2013, 08:23:04 am »
Quote
If you can add a RenderImage to SFML2.1
RenderImage is RenderTexture. It was just renamed (because Image was renamed to Texture). And it was in early SFML 2.0, no in SFML 1.6.
Laurent Gomila - SFML developer

 

anything