glDrawArrays problems

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

Moderators: cheriff, TyRaNiD

Post Reply
lego
Posts: 43
Joined: Fri Oct 17, 2008 1:09 am

glDrawArrays problems

Post by lego »

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: 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&#40;"ogl", 0, 3, 5&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU&#41;;
PSP_HEAP_SIZE_KB&#40;-1024&#41;;
PSP_MAIN_THREAD_STACK_SIZE_KB&#40;1024&#41;;

#define printf pspDebugScreenPrintf


typedef struct &#123;
  unsigned int color;
  float x, y, z;
&#125; vertex_t;

uint32_t __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; c&#91;&#93; = &#123; 0xff0000ff,
                                              0xff00ff00,
                                              0xff00ff00&#125;;
uint16_t __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; t&#91;&#93; = &#123; 200, 200,
                                           300, 200,
                                           300, 100&#125;;

vertex_t __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; vvv&#91;&#93; = &#123;
  &#123;0xff00ff00, 100, 100, 0&#125;,
  &#123;0xff0000ff, 200, 200, 0&#125;,
  &#123;0xff0000ff, 100, 200, 0&#125;&#125;;


/*************************************************************
 * EXIT CALLBACK STUFF
 *************************************************************/
/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
  sceKernelExitGame&#40;&#41;;
  return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
  int cbid;

  cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
  sceKernelRegisterExitCallback&#40;cbid&#41;;

  sceKernelSleepThreadCB&#40;&#41;;

  return 0;

&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
  int thid = 0;

  thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
  if&#40;thid >= 0&#41; &#123;
    sceKernelStartThread&#40;thid, 0, 0&#41;;
  &#125;

  return thid;
&#125;
  

void test&#40;void&#41;
&#123;
  glInterleavedArrays&#40;GL_C4UB_V3F, 0, vvv&#41;;
  glDrawArrays&#40;GL_TRIANGLES, 0, 3&#41;;

  glFinish&#40;&#41;;
&#125;

void initgl&#40;void&#41;
&#123;
  glMatrixMode&#40;GL_PROJECTION&#41;;
  glLoadIdentity&#40;&#41;;
  glOrtho&#40;0.0, 480, 272, 0, -1, 1&#41;;
  //glFrustum&#40;0, 480, 0, 272, 0.9999, 100.0&#41;;


  glMatrixMode&#40;GL_MODELVIEW&#41;;
  glLoadIdentity&#40;&#41;;

  glViewport&#40;0, 0, 480, 272&#41;;

  glClearColor&#40;0.0, 0.0, 1.0, 0.0&#41;;
&#125;

int main&#40;void&#41;
&#123;
  SDL_Surface *scrn;


  SetupCallbacks&#40;&#41;;
  pspDebugScreenInit&#40;&#41;;

  if &#40; SDL_Init&#40;SDL_INIT_VIDEO&#41; &#41; &#123;
    fprintf&#40;stderr, "Error&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
    return 1;
  &#125;
  atexit&#40;SDL_Quit&#41;;

  if &#40; !&#40;scrn = SDL_SetVideoMode&#40;480, 272, 32, SDL_OPENGL&#41;&#41; &#41; &#123;
    fprintf&#40;stderr, "Set video Error&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
    return 2;
  &#125;

  initgl&#40;&#41;;

  glClear&#40;GL_COLOR_BUFFER_BIT&#41;;


  test&#40;&#41;;


  SDL_GL_SwapBuffers&#40;&#41;;

  sceKernelSleepThreadCB&#40;&#41;;

  return 0;
&#125;
Makefile:

Code: Select all

.PHONY&#58; myclean

MOUNTDIR &#58;= /media/usbflash
DESTDIR &#58;= $&#40;MOUNTDIR&#41;/psp/game5xx/glda
TARGET = ogl.c
OBJS = ogl.o
PSP-PREF = $&#40;shell psp-config --psp-prefix&#41;


CFLAGS += -O2 -G0 -Wall -I$&#40;PSP-PREF&#41;/include \
        -I/home/lego/work/psp/pspdev/psp/include/SDL
LDFLAGS &#58;=
LIBS =  -L$&#40;PSP-PREF&#41;/lib -L$&#40;shell psp-config --pspsdk-path&#41;/lib \
        -lSDL_ttf -lSDL -lglut -lGLU -lGL \
        -lfreetype -lpspvfpu -lm -lpspgu -lpspaudio -lpspwlan \
        -lpsphprm -lpsprtc 
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

BUILD_PRX = 1
PSP_FW_VERSION = 500
PSP_LARGE_MEMORY = 1

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = glda

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

myclean&#58;
        rm -f *~

install&#58; all
        mount $&#40;MOUNTDIR&#41;
        mkdir -p $&#40;DESTDIR&#41; || true
        cp EBOOT.PBP $&#40;DESTDIR&#41;/
        mkdir $&#40;DESTDIR&#41;/fonts && \
          cp /usr/share/fonts/truetype/freefont/Free&#123;Sans,Serif&#125;.ttf \
            $&#40;DESTDIR&#41;/fonts/ || \
          true
        umount $&#40;MOUNTDIR&#41;

uninstall&#58;
        mount $&#40;MOUNTDIR&#41;
        rm -rf $&#40;DESTDIR&#41;
Also, if I change test() to the following I see a very strange triangle:

Code: Select all

void test&#40;void&#41;
&#123;
  glEnableClientState&#40;GL_COLOR_ARRAY&#41;;
  glEnableClientState&#40;GL_VERTEX_ARRAY&#41;;

  glColorPointer&#40;4, GL_UNSIGNED_BYTE, 0, c&#41;;
  glVertexPointer&#40;3, GL_SHORT, 0, t&#41;;

  glDrawArrays&#40;GL_TRIANGLES, 0, 3&#41;;

  glFinish&#40;&#41;;
&#125;
Can anybody help me :-)?

Thanks.
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

It's probably better to use sceGu or sceGum code.

Code: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
lego
Posts: 43
Joined: Fri Oct 17, 2008 1:09 am

Post by lego »

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.
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

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: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
lego
Posts: 43
Joined: Fri Oct 17, 2008 1:09 am

Post by lego »

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.
Post Reply