Homebrew [dev] Problems with texture maps and objects

PrintHello

Active Member
OP
Newcomer
Joined
Feb 10, 2016
Messages
37
Trophies
0
Age
28
XP
149
Country
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:
T5tHsts.png


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
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,032
Country
United States
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:
T5tHsts.png


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
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
 

PrintHello

Active Member
OP
Newcomer
Joined
Feb 10, 2016
Messages
37
Trophies
0
Age
28
XP
149
Country

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,032
Country
United States
Yeah I set that up just before calling the constructor for the gameobject. Do I have to do this every frame or just once when the program starts?
Just once should be fine. You could check out the texture and pica shader using the pica debugger in citra.
 

PrintHello

Active Member
OP
Newcomer
Joined
Feb 10, 2016
Messages
37
Trophies
0
Age
28
XP
149
Country
Just once should be fine. You could check out the texture and pica shader using the pica debugger in citra.
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.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    HiradeGirl @ HiradeGirl: @Sonic Angel Knight :bortz2: