[dev] Problems with texture maps and objects

Discussion in '3DS - Homebrew Development and Emulators' started by PrintHello, Nov 9, 2016.

  1. PrintHello
    OP

    PrintHello Member

    Newcomer
    37
    15
    Feb 10, 2016
    Hey so I'm trying to write a backend for a game I might make and am running into some troubles which (to be honest is probably just me not understanding c++ very well) but nevertheless I have been stuck on it for a few days now with very minimal progress.

    Basically I have written up a GameObject class like unity which has a texture, a model, a position, and an update function which i can then attach more scripts to.

    However, I cannot to save my life figure out how to get the texture to map onto the object when its rendered on the screen. For example, here is the code relevant to loading the texture into the gameobject object:


    Code:
    /*
    * texture is a C3D_Tex object, and tex_bin is the u8* texture_bin pointer. I am using kitten_bin as per the example just for testing.
    */
    
    C3D_TexInit(&texture, 64,64,GPU_RGBA8);
    
    //This is essentially what C3D_TexUpload does except for some reason it throws a bunch of read/write errors in citra
    texture.data = linearAlloc(texture.size);
    memcpy(texture.data, tex_bin, texture.size);
    //
    
    C3D_TexSetFilter(&texture, GPU_LINEAR, GPU_NEAREST);
    
    And the code to render the object:

    Code:
    C3D_TexBind(0, &(texture));
    C3D_BufInfo* bufInfo = C3D_GetBufInfo();
    BufInfo_Init(bufInfo);
    BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 3, 0x210);
    C3D_DrawArrays(GPU_TRIANGLES, 0, model.size());
    
    And here is what happens trying to run it in citra:
    [​IMG]

    Which I have no clue what it means. Whats more is when I run it on actual hardware, the game doesn't lock up, it just puts a random colour, (or multiple colours at times) on the object which is not what I was wanting.

    I have tried various incarnations of manually setting up the C3D_Tex struct myself which albiet stopped the 3ds from locking up, still didnt fix the problem. And have also tried malloc where I put linearAlloc except citra spams "unknown getpointer" which I'm assuming means malloc isnt working and returns a null pointer?

    Would appreciate any feedback, even if its just to clean up my code because I am using this to learn c/c++.

    Peace
     
  2. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    Did you setup the texture environment? Without this texturing will not be enabled.
    Take a look at the textured cube example - https://github.com/devkitPro/3ds-examples/blob/master/graphics/gpu/textured_cube/source/main.c
     
  3. PrintHello
    OP

    PrintHello Member

    Newcomer
    37
    15
    Feb 10, 2016
  4. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    Just once should be fine. You could check out the texture and pica shader using the pica debugger in citra.
     
  5. PrintHello
    OP

    PrintHello Member

    Newcomer
    37
    15
    Feb 10, 2016
    I had a little play around with it just then but I'm not sure what I am looking for. I printed the address of the texture and tried to view it but it wont work.