Hi,
I am currently trying to draw a rectangle using Citro3D (I do not want to use some library like sf2d or pp2d) but when I call `C3D_DrawArrays()`, I get a segmentation fault. When I remove this line, the program runs fine, it just doesn't render anything (obviously).
Here is the code where it crashes:
The code I use to start the frame looks like this:
Does anybody know what I'm doing wrong?
~ StuntHacks
I am currently trying to draw a rectangle using Citro3D (I do not want to use some library like sf2d or pp2d) but when I call `C3D_DrawArrays()`, I get a segmentation fault. When I remove this line, the program runs fine, it just doesn't render anything (obviously).
Here is the code where it crashes:
Code:
m3d::Color color(0, 0, 0, 255);
m3d::Vertex* vertices = new Vertex[4];
if (vertices == nullptr) return;
vertices[0].position = (m3d::Vector3f){(float) 10, (float) 20, 0.5f};
vertices[1].position = (m3d::Vector3f){(float) 10 + m_width, (float) 20, 0.5f};
vertices[2].position = (m3d::Vector3f){(float) 10, (float) 20 + m_height, 0.5f};
vertices[3].position = (m3d::Vector3f){(float) 10 + m_width, (float) 20 + m_height, 0.5f};
vertices[0].color = color.getRgba8();
vertices[1].color = vertices[0].color;
vertices[2].color = vertices[0].color;
vertices[3].color = vertices[0].color;
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0);
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE);
C3D_AttrInfo* attrInfo = C3D_GetAttrInfo();
AttrInfo_Init(attrInfo);
AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3);
AttrInfo_AddLoader(attrInfo, 1, GPU_UNSIGNED_BYTE, 4);
C3D_BufInfo* bufInfo = C3D_GetBufInfo();
BufInfo_Init(bufInfo);
BufInfo_Add(bufInfo, &vertices, sizeof(m3d::Vertex), 2, 0x10);
C3D_DrawArrays(GPU_TRIANGLE_STRIP, 0, 4);
The code I use to start the frame looks like this:
Code:
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C3D_FrameDrawOn(m_targetBottom->getRenderTarget());
Does anybody know what I'm doing wrong?
~ StuntHacks