PVR PNG Difficulties.

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

PVR PNG Difficulties.

Post by JS Lemming »

Aight, Gyrovorbis told me how to work with PNGs with the PVR... but it didn't work. Here's teh code.

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;
}
Here is what the compiler barfed on me
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)
Any idea's on whats the problem?[/code]
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

GRRRRR!!!

Wrong forum. PVR should be the keyword!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

GyroVorbis wrote:GRRRRR!!!

Wrong forum. PVR should be the keyword!
You would have shot me even if I did post this on the DC forum. Because it had "programming" in it. And you know it.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

I wrote:I like to classify programming things that are hardwares specific as "DC Dev" material, and things that are general programming as "Programming Discussion"
See that? I hardly think that loading PNGs to the Dreamcast PVR is not hardware specific, thus it should be here.

I wouldn't of been all up in your grill if you had posted it here. That's where I said to post stuff like this. Don't give me that. :mrgreen:
Last edited by Falco Girgis on Mon Jan 17, 2005 6:58 pm, edited 1 time in total.
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Post by Tvspelsfreak »

You have to link to the png library.
Add -lpng to the link line in the makefile.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Really? I thought that was already in there. . .
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Tvspelsfreak wrote:You have to link to the png library.
Add -lpng to the link line in the makefile.
Well, I thought that would be easy... but from what I see, there are like 3 link lines in the make file:
CFLAGS = -I $(INCDIR) -I $(INCDIR2) -ml -m4-single-only -O2 -fno-builtin -fno-strict-aliasing -fomit-frame-pointer -fno-optimize-sibling-calls -nostartfiles -nostdlib -Wl -Ttext=0x8c010000
SFLAGS = -I $(INCDIR) -I $(INCDIR2) -little
LDFLAGS = -L $(LIBDIR) -L $(LIBDIR2) -lkallisti -lgcc -ltsunami -lk++ -lparallax -lpcx -lz -lm -Ttext=0x8c010000
Becuase I tried putting -lpng in each line different times... each resulting in utter failureness. Can you show me what the correct way to do looks like?
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Post by Tvspelsfreak »

The bottom one is the link line.
Unfortunately GCC can get real picky about the link order.
So therefore you can just use the same line as I gave GV a long time ago:
-lparallax -lpng -lz -lm -ltremor -lkallisti -lgcc -ltsunami -lk++ -lpcx -Ttext=0x8c010000
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Aight.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Hey, this is wierd. I made a new project in a different directory. I fixed the makefile just like the other one. AND I copyied the souce of the other one and put it into the other one, and the png of course. Now... the old one worked perfectly, as in it displayed the PNG... but this new one doesn't show the PNG.. the only thing that seems to work is the untextured color rectangle. Now, I do know that the new directory I'm using has spaces in some of the folder names... could that one thing cause a png to simply not show up on screen?? Doesn't seem logical.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

What does the transfer window say? It seems to me like what it says in this case would be pretty useful.

Try to get into the habit of always checking it if anything ever goes wrong.

Check it and lemme know if you see something similar to texture "/rd/whatever.png" could not be found.

You do have rd and it is named "romdisk", right?
Post Reply