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
  • Psionic Roshambo @ Psionic Roshambo:
    Maybe a ghost writer?
  • BigOnYa @ BigOnYa:
    "Oh my God the graphics are so realistic looking." Lol of course it was the shiznit back then tho.
  • BigOnYa @ BigOnYa:
    I've never stood in line overnight or for hours, to buy anything. I can just wait and buy it later.
  • RedColoredStars @ RedColoredStars:
    I have never done that either.
  • RedColoredStars @ RedColoredStars:
    closest ive done is getting to target a couple hours early in the moring to get some amiibos.
  • Xdqwerty @ Xdqwerty:
    Im back
  • RedColoredStars @ RedColoredStars:
    But that topic makes me sad. :(
  • RedColoredStars @ RedColoredStars:
    Abusive narcissistic ex shame guilted me into selling them becasue my gaming and interests were childish like a little kid collecting toys. :(
  • RedColoredStars @ RedColoredStars:
    I had soooooooooooo many of them. All still sealed.
    +1
  • RedColoredStars @ RedColoredStars:
    I eventually had to contact a domestic abuse advocate to help me get out of the apartment I was in a lease with her. And filed a restraining order on her cuz she kept harassing me after i left her.
  • Xdqwerty @ Xdqwerty:
    I didnt bring my Charger and nobody here has one compatible with my phone
  • RedColoredStars @ RedColoredStars:
    either you have usb C and no one else does, or everone else has usb c except you. haha
    +1
  • Xdqwerty @ Xdqwerty:
    @RedColoredStars, i don't have usb c
  • RedColoredStars @ RedColoredStars:
    That happened to me for like a year. lol. I was the only one of all my friends and family to still have an old phone.
  • Xdqwerty @ Xdqwerty:
    @RedColoredStars, my phone is from around 2019
  • RedColoredStars @ RedColoredStars:
    Mine was from 2017. lolol. I just got this new one like 6 months ago. Not even new, second hand cheapo $40 phone. But it has usb c. lol
  • RedColoredStars @ RedColoredStars:
    I cant justify $1k+ on a nice ass phone. I can spend that on a 75" tv screen. Why a 6" screen device cost me the same? lol
    +2
  • BigOnYa @ BigOnYa:
    I had a iPhone 5 for like 6 years, till last year, and had to get new phone, when phone companies stop using the cdna networks, which the iphone5 used.
  • K3Nv2 @ K3Nv2:
    A phone can do more than a TV
    +2
  • BigOnYa @ BigOnYa:
    These smart TVs are getting close tho. Gonna be like "back to future" TVs before long.
    +1
  • K3Nv2 @ K3Nv2:
    Nah a phones going to always be more powerful than a TV if the TVs $2grand maybe but why when I can put a smaller device in my pocket that does basically everything a TV already does
    +1
  • K3Nv2 @ K3Nv2:
    I can justify a decent $800 smartphone that'll last 3 years when I could get a 65" TV for $400 and buy a decent micro computer for $100 more
  • K3Nv2 @ K3Nv2:
    Tbf there are decent $400 smartphones in today's market that make top end spec phones unjust it's just what you want
    K3Nv2 @ K3Nv2: Tbf there are decent $400 smartphones in today's market that make top end spec phones unjust...