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

Author Topic: Texture loaded , drawn , but not shown on the screen  (Read 6443 times)

0 Members and 2 Guests are viewing this topic.

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Texture loaded , drawn , but not shown on the screen
« on: May 25, 2014, 06:33:20 pm »
I am coding a game , and just started some of the graphical part so I just started to try using SFML for it , but I had a bug where a sprite would not show on screen, so I tought that ther was bugs deep into my code , and so I made a fresh project with what could be considered like the most basic code to show a Sprite , but it is doing the same thing , and I can't understand why...

     Here is the basic code(even if you could guess it x) ):

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

using namespace std;
using namespace sf;

int main(){
    RenderWindow window(VideoMode(500,500),"Test");

    Texture lavaFlow;
    lavaFlow.loadFromFile("lavaFlow.png");

    Sprite lavaFlowSprite;
    lavaFlowSprite.setTexture(lavaFlow);

    while(window.isOpen()){
        Event event;

        while(window.pollEvent(event)){
            if(event.type == Event::Closed){
                window.close();
            }
            window.clear();

            window.draw(lavaFlowSprite);

            window.display();
        }
    }
    return 0;
}

And few things to know , since I am compiling on Debug , some of the error shows , so I know that the Image has been loaded , and the image was firts in jpeg so I thank that it was maybe a type problem , so I converted it into png

Thanks to anyone who could help me !

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Texture loaded , drawn , but not shown on the screen
« Reply #1 on: May 25, 2014, 06:52:25 pm »
Try
setTexture(LavaFlow, true)

That will reset the texture rect. If you never set the texture rect, nothing will be "cut out" from the texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #2 on: May 25, 2014, 06:52:57 pm »
window.clear();

window.draw(lavaFlowSprite);

window.display();
This stuff should not be in the event loop ;)
Failing to succeed does not mean failing to progress!

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #3 on: May 25, 2014, 07:58:34 pm »
Where should I put it for it to be refersehd  ??? ?

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #4 on: May 25, 2014, 08:02:58 pm »
@eXpl0it3r

This doesn't do anything : My screen is still a big black box

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: Texture loaded , drawn , but not shown on the screen
« Reply #5 on: May 25, 2014, 08:11:17 pm »
Where should I put it for it to be refersehd  ??? ?
If you don't know what the event loop is and since you set things up wrong, you should definitely read the official tutorials, it's all explained there.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #6 on: May 25, 2014, 09:35:56 pm »
Ok so looking at my code I understood the problem of it (for the event loop) , yeah my thing was in the wrong loop because it was being refreshed only on events so I bumped it little down , in the while window.isOpen() loop , but I still have a big black screen ........

Looking at the tutorials I saw the one on drawing shapes , so should I draw A ssquare and apply a texture to it instead ?

EDIT: Nevermind RectangleShape has the same problem, could it be the texture not loading properly ?
« Last Edit: May 25, 2014, 09:44:03 pm by traxys »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #7 on: May 25, 2014, 09:48:06 pm »
I'll just leave this here: https://github.com/SFML/SFML/wiki/FAQ#tr-grl-minimal
Reduce your code to a minimal example and you are likely to spot the bug. You are also likely to have a better piece of code to post and ask questions about that people will actually bother to read.

Edit: sorry, I meant this for a different thread. Still can't hurt though  ;)
Anyway, you can check if the texture loaded OK.
« Last Edit: May 25, 2014, 09:52:37 pm by Jesper Juhl »

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #8 on: May 25, 2014, 10:21:32 pm »
Is there anything for checking that the texture is loaded ? Not going throught a sprite , just cheking if there is a texture like with checking a size that is the size of the file you defined it with (in pixel) or if a pixel RGB is equal to the one on the original picture , because my code is nearrly the minimal , + texture&sprite defined + clean/draw/display

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #9 on: May 25, 2014, 10:24:10 pm »
sf::Texture's loadFromFile() member function returns a bool. You could start by checking that.

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #10 on: May 25, 2014, 10:32:31 pm »
The loading seems to be fine because this :

    if(!lavaFlow.loadFromFile("lavaFlow.png")){
        cout<<"Error"<<endl;
    }

doesn't print anything , but is the loading of a picture wich is 260*260 long take some time , or is it like 0.1 sec ?

EDIT : Nevermind ,even if the loading time was a bit long , It would not be over 23 minutes .....
« Last Edit: May 25, 2014, 10:55:36 pm by traxys »

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #11 on: May 26, 2014, 12:29:09 am »
Ok know I am trying to figure out if the the texture is correctly put on a Sprite , but I can't figure out how to checks it , anyone has an idea how could I do it ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Texture loaded , drawn , but not shown on the screen
« Reply #12 on: May 26, 2014, 08:10:42 am »
If you draw a simple shape and it doesn't show up something is wrong to begin with.

Is your graphics driver uptodate?
What's your GPU?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #13 on: May 26, 2014, 07:15:35 pm »
My drivers could be wrong because I had problemens with them before(With a GPU that was not seen by my OS), but I have built SFML from the sources with MinGW , could It generate some problems ? And I am on a Laptop with the Graphical part of a CPU and a Radeon HD 7600M with up to date drivers. I am going to try deactivating one or the other.
« Last Edit: May 26, 2014, 07:35:04 pm by traxys »

traxys

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture loaded , drawn , but not shown on the screen
« Reply #14 on: May 26, 2014, 07:29:43 pm »
Ok so If I have just my GPU activated I get a SIGSEGV in the SFML code Oo :

#0 ??   ?? () (??:??)
#1 68ED4511   sf::RenderTarget::applyBlendMode(this=0x28fcc0, mode=...) (C:\Users\qbsec_000\Desktop\SFML\src\SFML\Graphics\RenderTarget.cpp:431)
#2 68ED413C   sf::RenderTarget::resetGLStates(this=0x28fcc0) (C:\Users\qbsec_000\Desktop\SFML\src\SFML\Graphics\RenderTarget.cpp:362)
#3 68ED39C9   sf::RenderTarget::draw(this=0x28fcc0, vertices=0x5047f8, vertexCount=32, type=sf::TrianglesFan, states=...) (C:\Users\qbsec_000\Desktop\SFML\src\SFML\Graphics\RenderTarget.cpp:211)
#4 68EDD30B   sf::VertexArray::draw(this=0x28fc48, target=..., states=...) (C:\Users\qbsec_000\Desktop\SFML\src\SFML\Graphics\VertexArray.cpp:147)
#5 68ED3963   sf::RenderTarget::draw(this=0x28fcc0, drawable=..., states=...) (C:\Users\qbsec_000\Desktop\SFML\src\SFML\Graphics\RenderTarget.cpp:185)
#6 68EDA437   sf::Shape::draw(this=0x28fb7c, target=..., states=...) (C:\Users\qbsec_000\Desktop\SFML\src\SFML\Graphics\Shape.cpp:219)
#7 68ED3963   sf::RenderTarget::draw(this=0x28fcc0, drawable=..., states=...) (C:\Users\qbsec_000\Desktop\SFML\src\SFML\Graphics\RenderTarget.cpp:185)
#8 00401922   main() (C:\Users\qbsec_000\Traxys\Documents\Cpp\Programms\SFMLTest\main.cpp:24)

And AMD Catalyst says now that My drivers are bugged.....

EDIT : When I deactivated my AMD Car my laptop did a BSOD
« Last Edit: May 26, 2014, 07:33:37 pm by traxys »

 

anything