1. Jayenkai

    OP Jayenkai Makes Games
    Member

    Joined:
    Dec 25, 2007
    Messages:
    415
    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: Apr 13, 2018
  2. BubbleChien

    BubbleChien Newbie
    Newcomer

    Joined:
    Feb 23, 2018
    Messages:
    3
    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: Apr 13, 2018
    Jayenkai likes this.
  3. Jayenkai

    OP Jayenkai Makes Games
    Member

    Joined:
    Dec 25, 2007
    Messages:
    415
    Country:
    United Kingdom
    [​IMG]

    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
     
  4. BubbleChien

    BubbleChien Newbie
    Newcomer

    Joined:
    Feb 23, 2018
    Messages:
    3
    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.
     
  5. Jayenkai

    OP Jayenkai Makes Games
    Member

    Joined:
    Dec 25, 2007
    Messages:
    415
    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 :)

    [​IMG]
     
    BubbleChien likes this.
  6. realWinterMute

    realWinterMute GBAtemp Regular
    Member

    Joined:
    Feb 24, 2011
    Messages:
    113
    Country:
    We have something better than that we're trying to polish up for release.

    DM me.
     
  7. elhobbs

    elhobbs GBAtemp Advanced Fan
    Member

    Joined:
    Jul 28, 2008
    Messages:
    850
    Country:
    United States
    Better than Citro3d? Sounds good to me - can’t wait to see what it is.
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - Switching, Textures, Citro3D