Homebrew Citro3D - Switching Textures

Jayenkai

Makes Games
OP
Member
Joined
Dec 25, 2007
Messages
415
Trophies
0
Age
44
Location
Bolton, England
Website
AGameAWeek.com
XP
1,041
Country
United Kingdom
Having a very frustrating morning of development, this morning, so thought I should ask the community for guidance, since it's Friday 13th and I just know I'm going to break everything if I plough ahead like I currently am!!

DevKitPro - [current version as of April 13th 2018)
Citro3D - 1.3.1

I've got textures (spritesheets) loading in, and I can draw one at a time, but I need to draw more than one different spritesheet in the frame at once.

I've got my spritesheet textures loaded into static C3D_Tex spritesheet_tex[105];, from where I'm starting a Frame, setting the target, splodging vertexes into the array, and then drawing the array.

C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C3D_FrameDrawOn(target);
// Update the uniforms
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection);
// Draw the VBO
C3D_DrawArrays(GPU_TRIANGLES, 0, numSprites);
C3D_FrameEnd(0);

The challenge I'm having is figuring out where and how to change the texture midway through.
eg, imagine the first 50 sprites are enemy sprites from spritesheet_tex[1], next 20 are bullets from spritesheet_tex[2], and the last couple are the player on spritesheet_tex[0]..

I've worked out that changing the TexBind will do *something* but it seems to result in the system trying to draw all the textures at once!! Bit chaotic.

I'm currently wondering if the C3D_FrameEnd and C3D_FrameBegin might act like OpenGL's glEnd and glBegin, but with them having the word "Frame" in there, I'm slightly worried that it might be doing something else, and I'll be slowing the whole thing down a bit..
(Having now tried this.. .. No, that's not it!!)

So, basically, what's the best technique for flicking through different spritesheets using C3D?

Any and all help would be greatly appreciated.
Thanks!
 
Last edited by Jayenkai, , Reason: Additional Testing

BubbleChien

New Member
Newbie
Joined
Feb 23, 2018
Messages
3
Trophies
0
Age
34
XP
140
Country
France
It's fine to switch textures using C3D_TexBind.

A simple example of what you'd typically do is :
Code:
// Start a new frame
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);

// Use the top screen
C3D_FrameDrawOn(top_screen);

// For each batch of sprites
{
    // Bind the texture to be used
    C3D_TexBind(0, &texture);

    // Bind the buffer and draw triangles
    C3D_SetBufInfo(&buffer);
    C3D_DrawArrays(GPU_TRIANGLES, start, size);
}

// End the frame
C3D_FrameEnd(0);

Hope it helps :-)
 
Last edited by BubbleChien,
  • Like
Reactions: Jayenkai

Jayenkai

Makes Games
OP
Member
Joined
Dec 25, 2007
Messages
415
Trophies
0
Age
44
Location
Bolton, England
Website
AGameAWeek.com
XP
1,041
Country
United Kingdom
Hmm_Textures_Blog_20180413A.png


I'm almost certain that it's some simple little command that I've left out, somewhere!! But having tested it, SetBufInfo wasn't the one, I'm afraid.

You can see what's happening in the image above. When I tell it to switch textures, it's DEFINITELY doing that. The text spritesheet is still showing up, and the "Bloke" spritesheet is also showing up correctly.
What's happening though, is that the vertex positions (and texture co-ords) are being overwritten from the start, after every change.

I've decided to start work on other aspects of the framework for now, and come back to this later. For now it's kinda working ok with Immediate mode, and I guess that'll have to do until I can figure this out!

Thanks for your help, though, and if you've any further suggestions, I'm happy to tweak :D
 

BubbleChien

New Member
Newbie
Joined
Feb 23, 2018
Messages
3
Trophies
0
Age
34
XP
140
Country
France
Thanks for the screenshot and explanations!

Are you updating the vertices inside the C3D_FrameBegin / C3D_FrameEnd pair?

I've noticed while using Citro3D that sometimes the vertices get weird when updated elsewhere.

As this is a thing that differs between immediate mode and vertex buffers this might be a lead.
 

Jayenkai

Makes Games
OP
Member
Joined
Dec 25, 2007
Messages
415
Trophies
0
Age
44
Location
Bolton, England
Website
AGameAWeek.com
XP
1,041
Country
United Kingdom
It's definitely all happening within the Begin/End. Not sure what's causing it. I've been ignoring it for today, though.
Got Immediate mode working, and a simple toggle to switch to VBO once I've got the thing working properly, so until then I've at least got working engine.

Thanks again for your help, and if I ever do figure it out, I'll be sure to let you know what it was. .. If I can remember what it was I tweaked at the time it magically started to work :)

3DS_Flappadiddle_001.png
 
  • Like
Reactions: BubbleChien

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    If your internet speeds are fast enough. Streaming 4k takes alot. I used to only have 20mb sec, and 4k struggled. Now I have 300mb sec and 4k plays fine.
    +1
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, i only have like 1 or 2 mb sec
  • BigOnYa @ BigOnYa:
    Did you feed the hamster in your internet router? It prob died and is running slow now.
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, why did you start saying my pc has a hamster in the first place?
    +1
  • BigOnYa @ BigOnYa:
    Its actua!ly just a old joke, meaning its slow. Was just kidding around with you.
    +1
  • BigOnYa @ BigOnYa:
    I bet @AncientBoi has some hamsters hidden somewhere tho....
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    I think Game streaming should work like this.... Local Hardware able the run the game fine, game engine and common assets stored locally, all FMV and music and textures could be streaming
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Some temporary storage
  • Xdqwerty @ Xdqwerty:
    also @BigOnYa im making some progress on my gdevelop project, implemented various mechanics
  • Psionic Roshambo @ Psionic Roshambo:
    They went all in on streaming, should have been more of a hybrid approach
    +1
  • BigOnYa @ BigOnYa:
    Or free government supplied high speed internet be nice also. Like Obama care. Xdqwerty that's cool, its time consuming but rewarding once done or playable, to see what you've made from scratch. Animations take forever, but worth it.
    +1
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, although the bullets are a bit buggy
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Not to mention this would be a massive pain to pirate
  • Xdqwerty @ Xdqwerty:
    @BigOnYa,
    and the visual aspect of the game is quite crude (the sprite that looks best is that of the protagonist just because he is a stickman with sunglasses)
    +1
  • BigOnYa @ BigOnYa:
    There is a bullets behaviour you assign to your character, that makes the code easier, under "behaviours"
  • Xdqwerty @ Xdqwerty:
    i meant that when the character is pointing to the right, the bullets spawn where they should, but when he is on the right, they move to the right but the spawn point is incorrect
  • BigOnYa @ BigOnYa:
    Itch.io has lots of free assets also. Under the bullets behavior tab, there is a "rotate bullets" option, can try that. Or in the code can try
    - fire bullet Player.X(PlayerDirection)
  • Xdqwerty @ Xdqwerty:
    im taking a break for today anyway
    +1
  • BigOnYa @ BigOnYa:
    YEa gotta after a while, looking at code for long periods will bug your eyes.
    +1
  • BigOnYa @ BigOnYa:
    That's cool tho, I'm proud of you going back to it, not giving up. It is difficult at first to learn, but fun once you get the hang of it. I think I've watched every tutorial video there is, but I still struggle sometimes to get stuff to work right. But gotta keep trying dif things, and eventually you will get it right.
    +1
  • K3Nv2 @ K3Nv2:
    Lol McDonald's has a grandma mcflurry
  • Xdqwerty @ Xdqwerty:
    @K3Nv2, furry grandma?
    Xdqwerty @ Xdqwerty: @K3Nv2, furry grandma?