I have a simple program, which must draws dots as on a chess-board in the top left corner of the screen. But instead, it draws two lines.
gu.c:
Code: Select all
#include <malloc.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
/*
#include <GL/gl.h>
#include <GL/glu.h>
*/
#include <math.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspthreadman.h>
#include <pspdisplay.h>
#include <pspnet_inet.h>
#include <pspnet.h>
#include <psputility.h>
#include <pspgu.h>
#include <pspgum.h>
#include <psputils.h>
PSP_MODULE_INFO("ogl", 0, 3, 5);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_KB(-1024);
PSP_MAIN_THREAD_STACK_SIZE_KB(1024);
#define printf pspDebugScreenPrintf
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
void *dList;// display List, used by sceGUStart
void *fbp0;// frame buffer
typedef struct {
  unsigned short u, v;
  float x, y, z;
} vertexT_t;
uint32_t __attribute__((aligned(16))) tmpt[] = {
  0xff0000ff, 0xff000000, 0xff00ff00, 0xff000000,
  0xff000000, 0xff0000ff, 0xff000000, 0xff00ff00,
  0xff00ff00, 0xff000000, 0xffff0000, 0xff000000,
  0xff000000, 0xff00ff00, 0xff000000, 0xffff0000};
/*************************************************************
 * EXIT CALLBACK STUFF
 *************************************************************/
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
  sceKernelExitGame();
  return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
  int cbid;
  cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
  sceKernelRegisterExitCallback(cbid);
  sceKernelSleepThreadCB();
  return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
  int thid = 0;
  thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
  if(thid >= 0) {
    sceKernelStartThread(thid, 0, 0);
  }
  return thid;
}
  
void initGU( void )
{ 
  // Init GU
  sceGuInit();
  sceGuStart( GU_DIRECT, dList );
    
  // Set Buffers
  sceGuDrawBuffer( GU_PSM_8888, fbp0, BUF_WIDTH );
  sceGuDispBuffer( SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
  sceGuDepthBuffer( (void*)0x110000, BUF_WIDTH);
  sceGuOffset( 2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2));
  sceGuViewport( 2048, 2048, SCR_WIDTH, SCR_HEIGHT);
  sceGuDepthRange( 65535, 0);
    
  // Set Render States
  sceGuScissor( 0, 0, SCR_WIDTH, SCR_HEIGHT);
  sceGuEnable( GU_SCISSOR_TEST );
  sceGuDepthFunc( GU_GEQUAL );
  sceGuEnable( GU_DEPTH_TEST );
  sceGuFrontFace( GU_CCW );
  sceGuShadeModel( GU_SMOOTH );
  sceGuEnable( GU_CULL_FACE );
  sceGuEnable( GU_CLIP_PLANES );
  sceGuFinish();
  sceGuSync(0,0);
 
  sceDisplayWaitVblankStart();
  sceGuDisplay(GU_TRUE);
  // finish
}
void setupProjection( void )
{
  // setup matrices for the triangle
  sceGumMatrixMode(GU_PROJECTION);
  sceGumLoadIdentity();
  sceGumOrtho(0, 480, 272 , 0, -1, 1);
  //  sceGumPerspective( 75.0f, 16.0f/9.0f, 0.5f, 1000.0f);
 
  sceGumMatrixMode(GU_VIEW);
  sceGumLoadIdentity();
 
  sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 1.0f, 0.0f ) ); 
  sceGuClearDepth(0);
  sceGumMatrixMode(GU_MODEL);
  sceGumLoadIdentity();
}
int main(void)
{
  SetupCallbacks();
  pspDebugScreenInit();
  if ( SDL_Init(SDL_INIT_VIDEO) ) {
    printf("Error: %s\n", SDL_GetError());
    return 1;
  }
  dList = memalign(16, 524288);
  initGU();
  setupProjection();
  sceGuStart(GU_DIRECT, dList);
    sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
    sceGuCopyImage(GU_PSM_8888, 0, 0, 4, 4, 4,
                   (void*)tmpt,
                   1, 1, 512, (void*)0x4000000);
  sceGuFinish();
  sceGuSync(0, 0);
  sceDisplayWaitVblankStart();
  sceGuSwapBuffers();
  sceKernelSleepThreadCB();
  return 0;
}
Code: Select all
.PHONY: myclean
MOUNTDIR := /media/usbflash
DESTDIR := $(MOUNTDIR)/psp/game5xx/CopyImage_test
TARGET = gu.c
OBJS = gu.o
PSP-PREF = $(shell psp-config --psp-prefix)
CFLAGS += -O2 -G0 -Wall -I$(PSP-PREF)/include \
        -I/home/lego/work/psp/pspdev/psp/include/SDL
LDFLAGS :=
LIBS =  -L$(PSP-PREF)/lib -L$(shell psp-config --pspsdk-path)/lib \
        -lconfig \
        -lpng -lz -lSDL_ttf -lSDL -lglut -lGLU -lGL \
        -lfreetype -lpspvfpu -lpspgum -lm -lpspgu -lpspaudio -lpspwlan \
        -lpsphprm -lpsprtc 
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BUILD_PRX = 1
PSP_FW_VERSION = 500
PSP_LARGE_MEMORY = 1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = CopyImage test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
myclean:
        rm -f *~
install: all
        mount $(MOUNTDIR)
        mkdir -p $(DESTDIR) || true
        cp EBOOT.PBP $(DESTDIR)/
        umount $(MOUNTDIR)




