Screen flickers when rendering more than one sprite.

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Screen flickers when rendering more than one sprite.

Post by Dormoxx » Sat Feb 02, 2013 6:20 pm

Let me start of by saying I'm trying to make this:
http://www.youtube.com/watch?v=PYrS54WH96Q
for the DC.

So I've got two classes so far, Stick and Player. They both have their own draw function which looks kind of like this:

Code: Select all

void Stick::draw() {
    pvr_wait_ready();

    pvr_scene_begin();
    pvr_list_begin(PVR_LIST_TR_POLY);
    prepScene();
    pvr_list_finish();

    pvr_scene_finish();
}
The prepScene() function handles all of the pvr poly and vertex stuff.

So, my question is, do I have to have all of the prepScene() stuff in one pvr_scene_begin()/pvr_scene_finish() code block? Or am I missing something obvious?

Thanks in advance!
#PlaySkullgirls
TapamN
DCEmu Freak
DCEmu Freak
Posts: 57
Joined: Sun Oct 04, 2009 11:13 am
Has liked: 0
Been liked: 13 times

Re: Screen flickers when rendering more than one sprite.

Post by TapamN » Sat Feb 02, 2013 7:25 pm

Dormoxx wrote:So, my question is, do I have to have all of the prepScene() stuff in one pvr_scene_begin()/pvr_scene_finish() code block?
Yes. The scene_begin/finish stuff starts and ends one frame worth of data, so you're having it draw one frame with one sprite, then another frame with the other sprite.
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Screen flickers when rendering more than one sprite.

Post by Dormoxx » Sat Feb 02, 2013 7:40 pm

TapamN wrote:
Dormoxx wrote:So, my question is, do I have to have all of the prepScene() stuff in one pvr_scene_begin()/pvr_scene_finish() code block?
Yes. The scene_begin/finish stuff starts and ends one frame worth of data, so you're having it draw one frame with one sprite, then another frame with the other sprite.
Thanks.

Another question. Are there any examples that show how to render text to the VMU screen? From the examples that I've looked at you can render an image, but not text. Is there an example for that?
#PlaySkullgirls
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5486
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 4 times
Been liked: 25 times
Contact:

Re: Screen flickers when rendering more than one sprite.

Post by BlueCrab » Sat Feb 02, 2013 9:01 pm

Dormoxx wrote:Another question. Are there any examples that show how to render text to the VMU screen? From the examples that I've looked at you can render an image, but not text. Is there an example for that?
There's no example that I've seen of it, however it shouldn't be particularly difficult to draw your text string to an image that is usable by the VMU.
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Dormoxx's DC Questions.

Post by Dormoxx » Sat Feb 02, 2013 9:19 pm

BlueCrab wrote:
Dormoxx wrote:Another question. Are there any examples that show how to render text to the VMU screen? From the examples that I've looked at you can render an image, but not text. Is there an example for that?
There's no example that I've seen of it, however it shouldn't be particularly difficult to draw your text string to an image that is usable by the VMU.
Do you mean creating a text string and converting it at runtime? Or make an image file on my PC and send it to the VMU?

Where would I look for an example to get an idea on how to use it? I've just now learned (or am still learning, really) how to draw a PNG to the DC screen. <_>
#PlaySkullgirls
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5486
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 4 times
Been liked: 25 times
Contact:

Re: Dormoxx's DC Questions.

Post by BlueCrab » Sat Feb 02, 2013 9:41 pm

Dormoxx wrote:Do you mean creating a text string and converting it at runtime? Or make an image file on my PC and send it to the VMU?
Well, either would be easy, but I'd assume you're looking for the former, not the latter.
Where would I look for an example to get an idea on how to use it? I've just now learned (or am still learning, really) how to draw a PNG to the DC screen. <_>
Well... Do you have any other experience with C? As in, do you understand all the basics of how arrays and such work? The image you send to the VMU's screen is basically just an array of pixels. Once you understand how to relate that array to what you see on the screen, you should be able to figure out how to turn on and off individual pixels by manipulating it. Once you can do that, your next step would be to put together a simple font to use with it, and then take the font and draw the characters you want into the array to get your desired effect.

I don't have any real examples of how you'd go about doing that, other than basically explaining the steps I'd take to do so (as I did up above). You could try searching on the forum to get a start on figuring it out. I'm sure there's at least a couple of topics on drawing to the VMU screen. Search for "VMU screen" and restrict your search to this forum, and I'm sure you'll find some stuff that's useful.
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Dormoxx's DC Questions.

Post by Dormoxx » Sat Feb 02, 2013 9:59 pm

BlueCrab wrote:Well... Do you have any other experience with C? As in, do you understand all the basics of how arrays and such work?
Well, actually... no. I have 0 experience with C. C++ was the first compiled language that I learned.
BlueCrab wrote:The image you send to the VMU's screen is basically just an array of pixels. Once you understand how to relate that array to what you see on the screen, you should be able to figure out how to turn on and off individual pixels by manipulating it. Once you can do that, your next step would be to put together a simple font to use with it, and then take the font and draw the characters you want into the array to get your desired effect.
I get that I should learn more about array manipulation, but how do I transfer that into writing a font for the VMU?
BlueCrab wrote:I don't have any real examples of how you'd go about doing that, other than basically explaining the steps I'd take to do so (as I did up above). You could try searching on the forum to get a start on figuring it out. I'm sure there's at least a couple of topics on drawing to the VMU screen. Search for "VMU screen" and restrict your search to this forum, and I'm sure you'll find some stuff that's useful.
Okay, thanks. I'll get to learning more advance array manipulation ASAP!
Also, I'll probably contain all my DC dev questions to this topic to avoid bloating the forum. :P

offtopic edit: Is your avatar from the anime I think it's from? Because it's one of my favorite animes, ever.:P
#PlaySkullgirls
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5486
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 4 times
Been liked: 25 times
Contact:

Re: Dormoxx's DC Questions.

Post by BlueCrab » Sat Feb 02, 2013 10:30 pm

Dormoxx wrote:I get that I should learn more about array manipulation, but how do I transfer that into writing a font for the VMU?
Once you understand how the images sent to the VMU are formed, I think it should be a lot clearer.
offtopic edit: Is your avatar from the anime I think it's from? Because it's one of my favorite animes, ever.:P
Yes, it probably is from the anime you think it is from (as it is pretty unmistakable which one it is from if you've seen it).
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Dormoxx's DC Questions.

Post by Dormoxx » Sun Feb 03, 2013 11:54 pm

BlueCrab wrote:Once you understand how the images sent to the VMU are formed, I think it should be a lot clearer.
Okay. Sounds good. I do have another question though.

I'm ordering the SD card adapter in a few days, mainly because burning CDs is getting really tedious and quite annoying. So my question is: is there a way to get debug output from the SD card? Something like printing to a text file? I tried searching the forum, but didn't really get a definite answer.
#PlaySkullgirls
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5486
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 4 times
Been liked: 25 times
Contact:

Re: Screen flickers when rendering more than one sprite.

Post by BlueCrab » Mon Feb 04, 2013 12:33 am

Well, natively, KallistiOS doesn't support writing to the SD card at the moment. It is being worked on (by me, by the way).

There is a fork of the KOS repo that does support SD card writing, but it is not as up-to-date as the official repo.

What might be a better approach is to use the framebuffer console to either draw to the screen or to a texture or something that you can display as needed. There are a couple of examples showing how to set up the framebuffer console, although they all set it up for a fullscreen draw. The page I linked to up there has the documentation of how to set it up for a non-fullscreen drawing. Basically, if you want to draw to a texture, allocate it with pvr_mem_malloc() as appropriate, and pass that as t to that function. The rest of the parameters should be relatively easy to figure out, and will (of course) depend on how big of a texture you allocate. Then, you can draw it to the screen just like any other texture (like what you get with PNG reading).
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Screen flickers when rendering more than one sprite.

Post by Dormoxx » Mon Feb 04, 2013 2:09 am

BlueCrab wrote:Well, natively, KallistiOS doesn't support writing to the SD card at the moment. It is being worked on (by me, by the way).

There is a fork of the KOS repo that does support SD card writing, but it is not as up-to-date as the official repo.
Well... shit.

The reason I wanted to use text output is because since KOS is new to me, I tend to screw up a lot. By that I mean when I try something new that I don't know how to fully implement, my program crashes back to the DC Hakker menu. Commenting out code, recompiling and burning to a CD is a very crappy way of debugging.

I suppose I'll have to fork out the cash for a LAN adapter. <_>
(Oh well, at least I'll be able to get live debugging output ^_^)
#PlaySkullgirls
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5486
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 4 times
Been liked: 25 times
Contact:

Re: Screen flickers when rendering more than one sprite.

Post by BlueCrab » Mon Feb 04, 2013 8:37 am

Dormoxx wrote:The reason I wanted to use text output is because since KOS is new to me, I tend to screw up a lot. By that I mean when I try something new that I don't know how to fully implement, my program crashes back to the DC Hakker menu. Commenting out code, recompiling and burning to a CD is a very crappy way of debugging.
I probably spent my first 6-9 months of Dreamcast programming doing things that way. Released a few things that I debugged that way back in the day. :wink:

That said, like I pointed out, the framebuffer console can help out a lot. You can get text output on the screen, and you can confine it to only parts of the screen.
I suppose I'll have to fork out the cash for a LAN adapter. <_>
(Oh well, at least I'll be able to get live debugging output ^_^)
If you're serious about doing Dreamcast stuff, it's definitely preferable to have some sort of Broadband adapter or Lan Adapter (they're two different pieces of hardware, after all) to do the debugging work with (or the ellusive Coder's Cable, which used to be the MUCH cheaper option).
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Screen flickers when rendering more than one sprite.

Post by Dormoxx » Mon Feb 04, 2013 12:39 pm

BlueCrab wrote:I probably spent my first 6-9 months of Dreamcast programming doing things that way. Released a few things that I debugged that way back in the day. :wink:
Dear god, man! I can't... I don't even... :o
BlueCrab wrote:If you're serious about doing Dreamcast stuff, it's definitely preferable to have some sort of Broadband adapter or Lan Adapter (they're two different pieces of hardware, after all) to do the debugging work with (or the ellusive Coder's Cable, which used to be the MUCH cheaper option).
Yeah, I am serious about DC dev. I grew up with this console, man! :grin:
It's the only homebrew community that I know of that has such a great community and well developed library.

I'm probably going to get the LAN adapter because it's cheaper. Though, shoving out an extra 50 bucks to play PSO online again would be quite amazing...
I didn't consider the coders cable an option because my PC doesn't have the required port. Plus, I don't know anything about building circuits. >_>
#PlaySkullgirls
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Screen flickers when rendering more than one sprite.

Post by Dormoxx » Mon Feb 04, 2013 6:48 pm

Okay. I know it's probably something obvious, but I'm at a standstill here. I've got the player and stick rendered, but for some reason, after the first collision, the collision code isn't called anymore.

Main Loop:

Code: Select all

while(!player.done) {
        player.handleInput();
        gamemanager.drawScene(player, stick);
        if(gamemanager.isCollision(player, stick)) {
            printf("if called\n");
            stick.generateNewCoordinates();
        }
    }
GameManager::isCollision():

Code: Select all

isCollision(Player& p, Stick& s)
    {
        if(p.getX() < s.getX() + 64 &&
           p.getX() + 32 > s.getY() &&
           p.getY() < s.getY() + 64 &&
           p.getY() + 64 > s.getY())
        {
            return true;
        }
        return false;
    }
Stick::generateNewCoordinates():

Code: Select all

generateNewCoordinates() {
    x = (rand() % (640 - 32));
    y = (rand() % (480 - 32));
    printf("%i", x);
    printf("\n");
    printf("%i", y);
    printf("\n\n");

}
I'm printing the x and y to the console to check if the collision code should be called (and it should) but it's not. Any and all help with this is appreciated. :mrgreen:

Full Source

edit: I'm using an emulator until I can order the BBA or LAN adapter.
#PlaySkullgirls
User avatar
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1808
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has liked: 0
Been liked: 0
Contact:

Re: Screen flickers when rendering more than one sprite.

Post by GyroVorbis » Tue Feb 05, 2013 1:49 pm

It isn't that your collision function isn't being invoked.
Dormoxx wrote:

Code: Select all

isCollision(Player& p, Stick& s)
    {
        if(p.getX() < s.getX() + 64 &&
           p.getX() + 32 > s.getY() &&
           p.getY() < s.getY() + 64 &&
           p.getY() + 64 > s.getY())
        {
            return true;
        }
        return false;
    }
Your algorithm is wrong. The second condition in the if statement should be comparing against x.getX() instead of s.getY()

Code: Select all

p.getX() + 32 > s.getX() &&
I'm not sure what your exact development setup is, but printf() is not reliable for debugging like that. Your string is copied to an internal buffer, which accumulates and is later flushed to stdout in bulk.

If you need your printf()s to be flushed immediately like that, use fflush(stdout) after each printf() call. Also, std::endl automatically flushes the buffer if you're using C++ (which you are). :mrgreen:
Elysian Shadows - "Next-Gen" 2D/3D RPG coming to Sega Dreamcast, Steam, OUYA, and Smartphones
Image
http://www.elysianshadows.com
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Screen flickers when rendering more than one sprite.

Post by Dormoxx » Tue Feb 05, 2013 1:56 pm

GyroVorbis wrote:It isn't that your collision function isn't being invoked.
Your algorithm is wrong. The second condition in the if statement should be comparing against x.getX() instead of s.getY()

Code: Select all

p.getX() + 32 > s.getX() &&
Shit. I knew it would be something like that. I guess it was just that I had been looking at the same code for hours on hours. Thanks Gyro! :mrgreen:

Edit::
GyroVorbis wrote:I'm not sure what your exact development setup is, but printf() is not reliable for debugging like that. Your string is copied to an internal buffer, which accumulates and is later flushed to stdout in bulk.

If you need your printf()s to be flushed immediately like that, use fflush(stdout) after each printf() call. Also, std::endl automatically flushes the buffer if you're using C++ (which you are). :mrgreen:
And I was using printf() because I was just getting really frustrated because it wasn't working. Thanks for letting me know about the buffer!:D
#PlaySkullgirls
User avatar
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1808
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has liked: 0
Been liked: 0
Contact:

Re: Screen flickers when rendering more than one sprite.

Post by GyroVorbis » Tue Feb 05, 2013 2:13 pm

I don't blame you. I remember doing the same thing. If you don't think the function is ever being called, because you don't see your printf()s happening, there's no real reason to check the logic of your algorithm... :lol:

That's why I make all debug logs explicitly call fflush() after every print call.
Elysian Shadows - "Next-Gen" 2D/3D RPG coming to Sega Dreamcast, Steam, OUYA, and Smartphones
Image
http://www.elysianshadows.com
Ayla
Insane DCEmu
Insane DCEmu
Posts: 140
Joined: Thu Apr 03, 2008 7:01 am
Has liked: 0
Been liked: 1 time
Contact:

Re: Screen flickers when rendering more than one sprite.

Post by Ayla » Tue Feb 05, 2013 2:57 pm

Or just use fprintf(stderr, ...) as it is flushed after each call.
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Screen flickers when rendering more than one sprite.

Post by Dormoxx » Tue Feb 05, 2013 7:15 pm

I've moved on sound and (of course :| ) am running into problems.

I looked at the 'hello-ogg' example and basically copy-pasted that code into my program. The music plays, but it loops the first second of the song. Would that be a problem with my audio file or the way my code is written?

In GameManager Constructor:

Code: Select all

        snd_stream_init();
        sndoggvorbis_init();
        sndoggvorbis_start("/rd/bgmusic.ogg", 1);
In GameManager Destructor

Code: Select all

        sndoggvorbis_stop();
        sndoggvorbis_shutdown();
        snd_stream_shutdown();
Also, how do I play a less than one second long sound effect? I tried using sndoggvorbis_start("/rd/itemGet.ogg", 0), but it doesn't play it.

Thanks again, everyone for your help! :grin:
#PlaySkullgirls
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

Re: Screen flickers when rendering more than one sprite.

Post by Dormoxx » Mon Feb 11, 2013 2:53 pm

bump?
#PlaySkullgirls
Post Reply