Homebrew Homebrew game Help: Citro3d not rendering anything

MinedGamer

Member
OP
Newcomer
Joined
Jan 12, 2021
Messages
7
Trophies
0
Age
20
XP
67
Country
Canada
Hi, I have set up the render targets on my project and everything but nothing appears!
All I'm trying to do right now is render the background color.
Here is what I'm doing:
defining CLEAR_COLOR : #define CLEAR_COLOR 0x00FFFFFF
Initializing graphics
Initializing C3D
creating both left and right targets : C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
linking both target to the screen : C3D_RenderTargetSetOutput(targetl, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);
starting to draw : C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
clearing both targets: C3D_RenderTargetClear(targetl, C3D_CLEAR_ALL, CLEAR_COLOR, 0);
finishing to draw : C3D_FrameEnd(0);

The whole thing is written in c++.
Relevent code:
Header:
Code:
#define DISPLAY_TRANSFER_FLAGS \
    (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \
    GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \
    GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))

#define CLEAR_COLOR 0x00FFFFFF

class Renderer {
private:
    // matrices
    C3D_Mtx ProjL, ProjR;
    C3D_Mtx view;

    C3D_Mtx material =
    {
        {
        { { 0.0f, 0.4f, 0.4f, 0.4f } }, // Ambient
        { { 0.0f, 0.4f, 0.4f, 0.4f } }, // Diffuse
        { { 0.0f, 0.8f, 0.8f, 0.8f } }, // Specular
        { { 1.0f, 0.0f, 0.0f, 0.0f } }, // Emission
        }
    };

    // render targets
    C3D_RenderTarget* targetl;
    C3D_RenderTarget* targetr;

    // shader
    Shader sha;

    // iod
    float iod;

    // texture manager reference
    textureManager* texMan;

    // vertex buffer object
    void* vbo;

public:
    // initialize and stop
    Renderer(textureManager* nTexMan);
    Renderer();
    void stop();

    // render to screen
    void renderBegin();
    void renderStop();

    // render model
    void clear();
    void render(C3D_Mtx *modelMtx, Model *model);

    // update variables
    void updateIod(float nIod);
    void setTextureManager(textureManager* nTexMan) { texMan = nTexMan; }

    // view
    void cameraGetViewMatrix(Camera* cam) { cam->getMatrix(&view); }
};

.cpp file:
Code:
#include "Renderer.h"
Renderer::Renderer() {
    // initialize graphics
    gfxInitDefault();
    gfxSet3D(true);
    C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);

    // debug console
    consoleInit(GFX_BOTTOM, NULL);
    printf("Called constructor \n");

    // initialize render targets
    targetl = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
    targetr = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
    C3D_RenderTargetSetOutput(targetl, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);
    C3D_RenderTargetSetOutput(targetr, GFX_TOP, GFX_RIGHT, DISPLAY_TRANSFER_FLAGS);
    if (targetl->linked && targetr->linked) {
        printf("Linked targets \n");
    }

    // initialize fragment shader
    C3D_TexEnv* env = C3D_GetTexEnv(0);
    C3D_TexEnvInit(env);
    C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PRIMARY_COLOR);
    C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);

    // iod
    iod = 0.f;

    // texture manager
    texMan = NULL;
}

void Renderer::renderStop() {
    C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
    C3D_RenderTargetClear(targetl, C3D_CLEAR_ALL, CLEAR_COLOR, 0);
    C3D_RenderTargetClear(targetr, C3D_CLEAR_ALL, CLEAR_COLOR, 0);
    C3D_FrameEnd(0);
    printf("Render end \n");

    gfxFlushBuffers();
    gfxSwapBuffers();

    gspWaitForVBlank();
}

I have tried putting everything in the same function to if it would work but still nothing.
I know the code is running and graphics are initialized because the console on the bottom screen is being updated.
I don't know what I am missing here.
Please help.
 
Last edited by MinedGamer,

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,032
Country
United States
Hi, I have set up the render targets on my project and everything but nothing appears!
All I'm trying to do right now is render the background color.
Here is what I'm doing:
defining CLEAR_COLOR : #define CLEAR_COLOR 0x00FFFFFF
Initializing graphics
Initializing C3D
creating both left and right targets : C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
linking both target to the screen : C3D_RenderTargetSetOutput(targetl, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);
starting to draw : C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
clearing both targets: C3D_RenderTargetClear(targetl, C3D_CLEAR_ALL, CLEAR_COLOR, 0);
finishing to draw : C3D_FrameEnd(0);

The whole thing is written in c++.
Relevent code:
Header:
Code:
#define DISPLAY_TRANSFER_FLAGS \
    (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \
    GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \
    GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))

#define CLEAR_COLOR 0x00FFFFFF

class Renderer {
private:
    // matrices
    C3D_Mtx ProjL, ProjR;
    C3D_Mtx view;

    C3D_Mtx material =
    {
        {
        { { 0.0f, 0.4f, 0.4f, 0.4f } }, // Ambient
        { { 0.0f, 0.4f, 0.4f, 0.4f } }, // Diffuse
        { { 0.0f, 0.8f, 0.8f, 0.8f } }, // Specular
        { { 1.0f, 0.0f, 0.0f, 0.0f } }, // Emission
        }
    };

    // render targets
    C3D_RenderTarget* targetl;
    C3D_RenderTarget* targetr;

    // shader
    Shader sha;

    // iod
    float iod;

    // texture manager reference
    textureManager* texMan;

    // vertex buffer object
    void* vbo;

public:
    // initialize and stop
    Renderer(textureManager* nTexMan);
    Renderer();
    void stop();

    // render to screen
    void renderBegin();
    void renderStop();

    // render model
    void clear();
    void render(C3D_Mtx *modelMtx, Model *model);

    // update variables
    void updateIod(float nIod);
    void setTextureManager(textureManager* nTexMan) { texMan = nTexMan; }

    // view
    void cameraGetViewMatrix(Camera* cam) { cam->getMatrix(&view); }
};

.cpp file:
Code:
#include "Renderer.h"
Renderer::Renderer() {
    // initialize graphics
    gfxInitDefault();
    gfxSet3D(true);
    C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);

    // debug console
    consoleInit(GFX_BOTTOM, NULL);
    printf("Called constructor \n");

    // initialize render targets
    targetl = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
    targetr = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
    C3D_RenderTargetSetOutput(targetl, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);
    C3D_RenderTargetSetOutput(targetr, GFX_TOP, GFX_RIGHT, DISPLAY_TRANSFER_FLAGS);
    if (targetl->linked && targetr->linked) {
        printf("Linked targets \n");
    }

    // initialize fragment shader
    C3D_TexEnv* env = C3D_GetTexEnv(0);
    C3D_TexEnvInit(env);
    C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PRIMARY_COLOR);
    C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);

    // iod
    iod = 0.f;

    // texture manager
    texMan = NULL;
}

void Renderer::renderStop() {
    C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
    C3D_RenderTargetClear(targetl, C3D_CLEAR_ALL, CLEAR_COLOR, 0);
    C3D_RenderTargetClear(targetr, C3D_CLEAR_ALL, CLEAR_COLOR, 0);
    C3D_FrameEnd(0);
    printf("Render end \n");

    gfxFlushBuffers();
    gfxSwapBuffers();

    gspWaitForVBlank();
}

I have tried putting everything in the same function to if it would work but still nothing.
I know the code is running and graphics are initialized because the console on the bottom screen is being updated.
I don't know what I am missing here.
Please help.
just a quick look but I dont think you should call the following with citro3d
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();

also full source would be helpful - something I can compile
 
Last edited by elhobbs,

MinedGamer

Member
OP
Newcomer
Joined
Jan 12, 2021
Messages
7
Trophies
0
Age
20
XP
67
Country
Canada
just a quick look but I dont think you should call the following with citro3d
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();

also full source would be helpful - something I can compile
I tried removing:
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();

nothing changed. The console still works but nothing on the top screen.
I posted the source code on https://www.mediafire.com/file/xfllbmvn1oii06d/SMOdemake.rar/file
Warning tho, it is quite messy as I am using visual studio as an editor.

I also don't seem to be affected by this bug as the console dosen't stop running.
 
Last edited by MinedGamer,

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,032
Country
United States
I tried removing:
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();

nothing changed. The console still works but nothing on the top screen.
I posted the source code on https://www.mediafire.com/file/xfllbmvn1oii06d/SMOdemake.rar/file
Warning tho, it is quite messy as I am using visual studio as an editor.

I also don't seem to be affected by this bug as the console dosen't stop running.
there is nothing in that archive to compile for the 3ds - no makefile. how do you compile this?
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,032
Country
United States

MinedGamer

Member
OP
Newcomer
Joined
Jan 12, 2021
Messages
7
Trophies
0
Age
20
XP
67
Country
Canada
you need to call C3D_FrameDrawOn after you clear the buffers - citro3d does not seem to like it if you dont do this.

C3D_RenderTargetClear(targetl, C3D_CLEAR_ALL, CLEAR_COLOR, 0);
C3D_FrameDrawOn(targetl);

add it for the right screen too.
Alright! It worked! Thanks for the help =)
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: So negative