PVR PNG Difficulties.
Posted: Mon Jan 17, 2005 4:24 pm
Aight, Gyrovorbis told me how to work with PNGs with the PVR... but it didn't work. Here's teh code.
Here is what the compiler barfed on me
Code: Select all
//this is needed by KOS
#define _arch_dreamcast
#include <kos.h>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <png/png.h>
extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);
int xpos = 1;
int ypos = 1;
int xvel = 2;
int yvel = 2;
//Convert
//z = 256 - z;
//255 = transparent
void draw_tr_quad(int x, int y, int z, int w, int h, int a, int r, int g, int b) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
pvr_poly_cxt_col(&cxt,PVR_LIST_TR_POLY);
pvr_poly_compile(&hdr,&cxt);
pvr_prim(&hdr,sizeof(hdr));
vert.argb = PVR_PACK_COLOR(a,r,g,b);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = x; // = x-(w/2);
vert.y = y; // = y-(h/2);
vert.z = z;
pvr_prim(&vert,sizeof(vert));
vert.x = x + w; // = x+(w/2);
vert.y = y; // = y-(h/2);
vert.z = z;
pvr_prim(&vert,sizeof(vert));
vert.x = x; // = x-(w/2);
vert.y = y + h; // = y+(h/2);
vert.z = z;
pvr_prim(&vert,sizeof(vert));
vert.x = x + w; // = x+(w/2);
vert.y = y + h; // y+(h/2);
vert.z = z;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert,sizeof(vert));
}
void DrawPNG(int x, int y, int w, int h, int scalex, int scaley, pvr_ptr_t GFX, int z, int a) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
pvr_poly_cxt_txr(&cxt,PVR_LIST_TR_POLY,PVR_TXRFMT_ARGB4444,w,h,GFX,PVR_FILTER_NONE);
pvr_poly_compile(&hdr,&cxt);
pvr_prim(&hdr,sizeof(hdr));
vert.argb = PVR_PACK_COLOR(a,1,1,1);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = x - (w/2) - scalex;
vert.y = y - (h/2) - scaley;
vert.z = z;
vert.u = 0.0;
vert.v = 0.0;
pvr_prim(&vert,sizeof(vert));
vert.x = x + (w/2) + scalex;
vert.y = y - (h/2) - scaley;
vert.z = z;
vert.u = 1.0;
vert.v = 0.0;
pvr_prim(&vert,sizeof(vert));
vert.x = x - (w/2) - scalex;
vert.y = y + (h/2) + scaley;
vert.z = z;
vert.u = 0.0;
vert.v = 1.0;
pvr_prim(&vert,sizeof(vert));
vert.x = x + (w/2) + scalex;
vert.y = y + (h/2) + scaley;
vert.z = z;
vert.u = 1.0;
vert.v = 1.0;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
}
void UpdateRect()
{
xpos = xpos + xvel;
ypos = ypos + yvel;
if(xpos < 0) { xpos = 0; xvel = -xvel; }
if(ypos < 0) { ypos = 0; yvel = -yvel; }
if(xpos > 640-100) { xpos = 640-100; xvel = -xvel; }
if(ypos > 480-100) { ypos = 480-100; yvel = -yvel; }
draw_tr_quad(xpos, ypos, 1, 100, 100, 1, 255, 255, 1);
}
void DrawFrame()
{
//Debug only: Shows how much lag between seens (red=good)
// vid_border_color(255, 0, 0);
pvr_wait_ready();
// vid_border_color(0, 255, 0);
vid_border_color(0, 0, 0);
pvr_scene_begin();
// Non-transparent graphics
pvr_list_begin(PVR_LIST_OP_POLY);
pvr_list_finish();
// Transparent graphics
pvr_list_begin(PVR_LIST_TR_POLY);
UpdateRect();
pvr_list_finish();
pvr_scene_finish();
}
int main()
{
srand(time(NULL));
vid_set_mode(DM_640x480, PM_RGB565);
pvr_init_defaults();
//Resets DC-Load when L,R,A,B,X,Y and Start is pressed
// cont_btn_callback(0, CONT_START | CONT_A | CONT_B | CONT_X | CONT_Y, (void (*)(unsigned char, long unsigned int))arch_exit);
cont_btn_callback(0, CONT_START | CONT_A | CONT_X , (void (*)(unsigned char, long unsigned int))arch_exit);
// pvr_ptr_t pic;
// pic = pvr_mem_malloc(256*256*2);
// png_to_texture("/rd/room.png", pic, PNG_FULL_ALPHA);
pvr_ptr_t blue_logo = pvr_mem_malloc(256*256*2);
png_to_texture("/rd/room.png", blue_logo, PNG_FULL_ALPHA);
while(1)
{
DrawFrame();
}
return 0;
}
Any idea's on whats the problem?[/code]Deleting intermediate files and output files for project 'PNG_Test - Win32 Debug'.
--------------------Configuration: PNG_Test - Win32 Debug--------------------
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
C:\DevKitDC\bin\createim C:\DreamCast\HomeBrew\PNG_Test\romdisk.img C:\DreamCast\HomeBrew\PNG_Test\romdisk
0 rom 41ec52b1 [0xffffffff, 0xffffffff] 37777777777, sz 0, at 0x0
1 . [0x1000 , 0x26892c30] 0040755, sz 0, at 0x20
1 .. [0x1000 , 0x12500c94] 0040755, sz 0, at 0x40 [link to 0x20 ]
1 room.bmp [0x19d3 , 0x32ea5c6e] 0100644, sz 196662, at 0x60
1 room.png [0x19d3 , 0x3205ec6e] 0100644, sz 2514, at 0x300c0
C:\DevKitDC\bin\createo C:\DreamCast\HomeBrew\PNG_Test\romdisk.img romdisk C:\DreamCast\HomeBrew\PNG_Test\romdisk.o
C:\DevKitDC\bin\g++ -o PNG_Test.elf romdisk.o startup.o PNG_Test.cpp -I C:\DevKitDC\include -I C:\DevKitDC\kernel\arch\dreamcast\include -ml -m4-single-only -O2 -fno-builtin -fno-strict-aliasing -fomit-frame-pointer -fno-optimize-sibling-calls -n
ostartfiles -nostdlib -Wl -Ttext=0x8c010000 -L C:\DevKitDC\lib -L C:\DevKitDC\sh-sega-dreamcast\lib -lkallisti -lgcc -ltsunami -lk++ -lparallax -lpcx -lz -lm -Ttext=0x8c010000
/cygdrive/c/DevKitDC/bin/../lib/gcc-lib/sh-sega-dreamcast/3.0.3/../../../../sh-sega-dreamcast/bin/ld: warning: cannot find entry symbol _start; defaulting to 8c010000
/cygdrive/c/WINDOWS/TEMP/ccZ7JC0R.o: In function `_main':
/cygdrive/c/WINDOWS/TEMP/ccZ7JC0R.o(.text+0x4b0): undefined reference to `_png_to_texture'
collect2: ld returned 1 exit status
NMAKE : fatal error U1077: 'C:\DevKitDC\bin\g++.exe' : return code '0x1'
Stop.
Error executing NMAKE.
PNG_Test.exe - 1 error(s), 1 warning(s)