A following code must draw a triangle. On a PC it have one green vertex and two red ones. But on a PSP all vertices are red. What am I doing wrong?
ogl.c:
Code: Select all
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_opengl.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>
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
typedef struct {
unsigned int color;
float x, y, z;
} vertex_t;
uint32_t __attribute__((aligned(16))) c[] = { 0xff0000ff,
0xff00ff00,
0xff00ff00};
uint16_t __attribute__((aligned(16))) t[] = { 200, 200,
300, 200,
300, 100};
vertex_t __attribute__((aligned(16))) vvv[] = {
{0xff00ff00, 100, 100, 0},
{0xff0000ff, 200, 200, 0},
{0xff0000ff, 100, 200, 0}};
/*************************************************************
* 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 test(void)
{
glInterleavedArrays(GL_C4UB_V3F, 0, vvv);
glDrawArrays(GL_TRIANGLES, 0, 3);
glFinish();
}
void initgl(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 480, 272, 0, -1, 1);
//glFrustum(0, 480, 0, 272, 0.9999, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, 480, 272);
glClearColor(0.0, 0.0, 1.0, 0.0);
}
int main(void)
{
SDL_Surface *scrn;
SetupCallbacks();
pspDebugScreenInit();
if ( SDL_Init(SDL_INIT_VIDEO) ) {
fprintf(stderr, "Error: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
if ( !(scrn = SDL_SetVideoMode(480, 272, 32, SDL_OPENGL)) ) {
fprintf(stderr, "Set video Error: %s\n", SDL_GetError());
return 2;
}
initgl();
glClear(GL_COLOR_BUFFER_BIT);
test();
SDL_GL_SwapBuffers();
sceKernelSleepThreadCB();
return 0;
}
Code: Select all
.PHONY: myclean
MOUNTDIR := /media/usbflash
DESTDIR := $(MOUNTDIR)/psp/game5xx/glda
TARGET = ogl.c
OBJS = ogl.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 \
-lSDL_ttf -lSDL -lglut -lGLU -lGL \
-lfreetype -lpspvfpu -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 = glda
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)/
mkdir $(DESTDIR)/fonts && \
cp /usr/share/fonts/truetype/freefont/Free{Sans,Serif}.ttf \
$(DESTDIR)/fonts/ || \
true
umount $(MOUNTDIR)
uninstall:
mount $(MOUNTDIR)
rm -rf $(DESTDIR)
Code: Select all
void test(void)
{
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, c);
glVertexPointer(3, GL_SHORT, 0, t);
glDrawArrays(GL_TRIANGLES, 0, 3);
glFinish();
}
Thanks.