 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Fri Oct 16, 2009 10:12 pm Post subject: glDrawArrays problems |
|
|
Hi.
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: |
#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;
}
|
Makefile:
| Code: |
.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)
|
Also, if I change test() to the following I see a very strange triangle:
| Code: |
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();
}
|
Can anybody help me :-)?
Thanks. |
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Sat Oct 17, 2009 1:24 am Post subject: |
|
|
It's probably better to use sceGu or sceGum code. _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Sat Oct 17, 2009 2:07 am Post subject: |
|
|
| jojojoris wrote: | | It's probably better to use sceGu or sceGum code. |
:-) If I will find how I can use freetype fonts with sceGu, I rewrite my program with sceGu + sceGum. |
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Sat Oct 17, 2009 3:05 am Post subject: |
|
|
Freetype just renders text as a bitmap which you can draw using the sceGu
You only have to do some reserch about the freetype API which isn't that difficult. _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
lego
Joined: 17 Oct 2008 Posts: 43
|
Posted: Sun Oct 18, 2009 3:19 am Post subject: |
|
|
| jojojoris wrote: | Freetype just renders text as a bitmap which you can draw using the sceGu
You only have to do some reserch about the freetype API which isn't that difficult. |
Thanks. I will try it. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|