C++ woes

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
solinent
Posts: 1
Joined: Sun Sep 21, 2008 2:34 am

C++ woes

Post by solinent »

I just installed the toolchain and psplinkusb to start developing for the psp (on my ubuntu system).

Anyways, I was messing around with the ortho example, trying to convert it into c++ code.

The following code doesn't draws debug info on the screen, but it doesn't draw the primitives, until I quit usbhostfs_pc. Then it immediately starts to draw the primitive.

When I don't use psplink to do this, nothing at all shows up on the screen.

Code:

Code: Select all

#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspgu.h>
#include <pspgum.h>

#include <iostream>
#include <cmath>
#include <cstdlib>

#include "../common/callbacks.h"
#include "../common/vram.h"

PSP_MODULE_INFO&#40;"Tetris", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

// This is a command list for sceGuStart, at arbitrary size
static unsigned int __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; list&#91;262144&#93;;

const int BUF_WIDTH = 512;
const int SCR_WIDTH = 480;
const int SCR_HEIGHT = 272;

//Vertex structure for a simple vertex.
struct Vertex
&#123;
	unsigned int color;
	float x, y ,z;
&#125;;

int main &#40;&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	setupCallbacks&#40;&#41;;

	// Setup Gu
	void* fbp0 = getStaticVramBuffer&#40;BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888&#41;;
	void* fbp1 = getStaticVramBuffer&#40;BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888&#41;;
	void* zbp = getStaticVramBuffer&#40;BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444&#41;;
 
	sceGuInit&#40;&#41;;
 
	sceGuStart&#40;GU_DIRECT,list&#41;;
	sceGuDrawBuffer&#40;GU_PSM_8888,fbp0,BUF_WIDTH&#41;;
	sceGuDispBuffer&#40;SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH&#41;;
	sceGuDepthBuffer&#40;zbp,BUF_WIDTH&#41;;
	sceGuOffset&#40;2048 - &#40;SCR_WIDTH/2&#41;,2048 - &#40;SCR_HEIGHT/2&#41;&#41;;
	sceGuViewport&#40;2048,2048,SCR_WIDTH,SCR_HEIGHT&#41;;
	sceGuDepthRange&#40;65535,0&#41;;
	sceGuScissor&#40;0,0,SCR_WIDTH,SCR_HEIGHT&#41;;
	sceGuEnable&#40;GU_SCISSOR_TEST&#41;;
	sceGuFrontFace&#40;GU_CW&#41;;
	sceGuShadeModel&#40;GU_SMOOTH&#41;;
	sceGuDisable&#40;GU_TEXTURE_2D&#41;;
	sceGuFinish&#40;&#41;;
	sceGuSync&#40;0,0&#41;;
 
	sceDisplayWaitVblankStart&#40;&#41;;
	sceGuDisplay&#40;GU_TRUE&#41;;

	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;
	
	Vertex __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; vertices &#91;4&#93; = 
	&#123;
    	&#123;0xFF0000FF, -5.0f, -5.0f, 0.0f&#125;, // Top, red
		&#123;0xFF00FFFF, -5.0f, 5.0f, 0.0f&#125;,
        &#123;0xFF00FF00, 5.0f, -5.0f, 0.0f&#125;, // Right, green
        &#123;0xFFFF0000, 5.0f, 5.0f, 0.0f&#125; // Left, blue
	&#125;;

	int frame = 0;
	float blockSize= 13.0f;
	ScePspFVector3 pos = &#123;240.0f, 136.0f, 0.0f&#125;;

	while &#40;running&#40;&#41;&#41;
	&#123;
		SceCtrlData pad;
		sceGuStart&#40;GU_DIRECT,list&#41;;

		sceCtrlPeekBufferPositive&#40;&pad, 1&#41;;

		if&#40;pad.Buttons & PSP_CTRL_UP&#41;
		sceCtrlPeekBufferPositive&#40;&pad, 1&#41;;

		if&#40;pad.Buttons & PSP_CTRL_UP&#41;
			//pos.z += 1.0f / 100.0f;
		if&#40;pad.Buttons & PSP_CTRL_DOWN&#41;
			//pos.z -= 1.0f / 100.0f;

		if&#40;abs&#40;pad.Lx-128&#41; > 32&#41;
			pos.x += &#40;&#40;pad.Lx-128&#41;/128.0f&#41;;
		if&#40;abs&#40;pad.Ly-128&#41; > 32&#41;
			pos.y += &#40;&#40;pad.Ly-128&#41;/128.0f&#41;;
			//pos.z += 1.0f / 100.0f;
		if&#40;pad.Buttons & PSP_CTRL_DOWN&#41;
			//pos.z -= 1.0f / 100.0f;

		if&#40;abs&#40;pad.Lx-128&#41; > 32&#41;
			pos.x += &#40;&#40;pad.Lx-128&#41;/128.0f&#41;;
		if&#40;abs&#40;pad.Ly-128&#41; > 32&#41;
			pos.y += &#40;&#40;pad.Ly-128&#41;/128.0f&#41;;

		// Clear the buffers
		sceGuClearColor&#40;0&#41;;
		sceGuClearDepth&#40;0&#41;;
		sceGuClear&#40;GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT&#41;;
		
		// Set ortho mode and load
		sceGumMatrixMode&#40;GU_PROJECTION&#41;;
		sceGumLoadIdentity&#40;&#41;;
		sceGumOrtho&#40;0, 480, 272, 0, -1, 1&#41;;

		sceGumMatrixMode&#40;GU_VIEW&#41;;
		sceGumLoadIdentity&#40;&#41;;
 
		sceGumMatrixMode&#40;GU_MODEL&#41;;
		sceGumLoadIdentity&#40;&#41;;

		// Draw primitives
		//Tetrominoe s&#40;Tetrominoe_I&#41;;
		

		sceGumTranslate&#40;&pos&#41;;
		//sceGumRotateZ&#40;frame*0.03f&#41;;

		sceGumDrawArray&#40;GU_TRIANGLES,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,1*4,0,vertices&#41;;

		// Finish and wait until display lists are done drawing
		sceGuFinish&#40;&#41;;
		sceGuSync&#40;0,0&#41;;

		pspDebugScreenSetOffset&#40;&#40;int&#41;fbp0&#41;;
		pspDebugScreenSetXY&#40;0,0&#41;;

		//pspDebugScreenPrintf&#40;"Frame&#58; %i", frame&#41;;
		pspDebugScreenPrintf&#40;"x&#58; %.2f y&#58; %.2f z&#58; %.2f",pos.x,pos.y,pos.z&#41;;

		sceDisplayWaitVblankStart&#40;&#41;;
		fbp0 = sceGuSwapBuffers&#40;&#41;;
		frame++;
	&#125;

	// Quit Gu
	sceGuTerm&#40;&#41;;

	// Exit game
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;
I have no idea what to do, and would like to use c++ rather than c.

In addition, when I set up code to call sceGumDrawArray more than once it only draws the last call to sceGumDrawArray (after I quit usbhostfs_pc, of course).

Thanks
Post Reply