So anyways, here is my graphics.h file, everything is in it. Can anyone point out what is causing me to have to set PIXEL_SIZE to 1 instead of 2?
Any help would be apreciated.
Code: Select all
//////////////////////////////////////////////////////////////////////////////////////////
// Graphics.h Version 1.3
// By Jason J. Owens
// August 28, 2005 10:27 AM
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef __GRAPHICS__
#define __GRAPHICS__
// Includes
#include <pspdisplay.h>
#include <pspge.h>
#include <png.h>
//////////////////////////////////////////////////////////////////////////////////////////
// Function Prototypes
void PlotPixel(int x,int y,int r,int g,int b);
void InitializeGraphics(int mode);
void PlotLine(int x0,int y0,int x1,int y1,int r,int g,int b);
void PlotCircle(int xcenter,int ycenter,int radius,int r,int g,int b);
void screenshot(const char* filename);
//////////////////////////////////////////////////////////////////////////////////////////
// #defines
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (1) /* change this if you change to another screenmode */
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
//////////////////////////////////////////////////////////////////////////////////////////
// Global Variables
u16 *VRAM=(void *)(0x44000000);
//////////////////////////////////////////////////////////////////////////////////////////
// Function Definitions
// Plots a pixel on the screen using x,y, and three 0-255 shade color attributes.
void PlotPixel(int x,int y,int r,int g,int b)
{
// Tests whether pixel is being drawn off-screen, and returns imediately if so.
if(x<0||x>479||y<0||y>271||r<0||r>255||g<0||g>255||b<0||b>255)
{
return;
}
int color=((b>>3)<<10) | ((g>>3)<<5) | (r>>3) | 0x8000; // Creates and stores color.
u16 *address=VRAM+((((512)*PIXEL_SIZE)*y)+x); // Caculates address of pixel.
*address=color; // Writes color code into address of the pixel.
}
//////////////////////////////////////////////////////////////////////////////////////////
// Plots a line according to the given values, startX, startY, endX, endY, and color: R,G,B.
void PlotLine(int x0,int y0,int x1,int y1,int r,int g,int b)
{
int dy = y1 - y0;
int dx = x1 - x0;
float t = (float) 0.5; // offset for rounding
PlotPixel(x0,y0,r,g,b);
// If endpoints are the same, then don't draw the line, just return.
if( dy == 0 && dx == 0 ) return;
if (abs(dx) > abs(dy)) // slope < 1
{
float m = (float) dy / (float) dx; // compute slope
t += y0;
dx = (dx < 0) ? -1 : 1;
m *= dx;
while (x0 != x1)
{
x0 += dx; // step to next x value
t += m; // add slope to y value
PlotPixel(x0,(int)t,r,g,b);
}
}
else // slope >= 1
{
float m = (float) dx / (float) dy; // compute slope
t += x0;
dy = (dy < 0) ? -1 : 1;
m *= dy;
while (y0 != y1)
{
y0 += dy; // step to next y value
t += m; // add slope to x value
PlotPixel((int)t,y0,r,g,b);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Plots a circle according to the given values, centerX, centerY, radius, and color: R,G,B.
void PlotCircle(int xcenter,int ycenter,int radius,int r,int g,int b)
{
int x=0;
int y=radius;
int p=3 - 2 * radius;
while(x <= y)
{
PlotPixel(xcenter+x,ycenter+y,r,g,b);
PlotPixel(xcenter-x,ycenter+y,r,g,b);
PlotPixel(xcenter+x,ycenter-y,r,g,b);
PlotPixel(xcenter-x,ycenter-y,r,g,b);
PlotPixel(xcenter+y,ycenter+x,r,g,b);
PlotPixel(xcenter-y,ycenter+x,r,g,b);
PlotPixel(xcenter+y,ycenter-x,r,g,b);
PlotPixel(xcenter-y,ycenter-x,r,g,b);
if(p < 0)
p += 4 * x++ + 6;
else
p += 4 * (x++ - y--) + 10;
}
}
///////////////////////////////////////////////////////////////////////////////////
// Initializes the PSP Display.
void InitializeGraphics(int mode)
{
sceDisplaySetMode(mode,SCR_WIDTH,SCR_HEIGHT); // Sets the display mode.
sceDisplaySetFrameBuf(VRAM,BUF_WIDTH,1,1); // Sets the address of the frame buffer.
}
//////////////////////////////////////////////////////////////////////////////////////////
// Saves a screenshot of the screen to filename.
void screenshot(const char* filename)
{
png_structp png_ptr;
png_infop info_ptr;
FILE* fp;
int i, x, y;
u16* data = VRAM;
int width=SCR_WIDTH;
int height=SCR_HEIGHT;
int linesize=BUF_WIDTH;
int saveAlpha=0;
u8* line;
if ((fp = fopen(filename, "wb")) == NULL) return;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) return;
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, width, height, 8,
saveAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
line = (u8*) malloc(width * (saveAlpha ? 4 : 3));
for (y = 0; y < height; y++) {
for (i = 0, x = 0; x < width; x++) {
u16 color = data[x + y * linesize];
int r = (color & 0x1f) << 3;
int g = ((color >> 5) & 0x1f) << 3 ;
int b = ((color >> 10) & 0x1f) << 3 ;
line[i++] = r;
line[i++] = g;
line[i++] = b;
if (saveAlpha) {
int a = color & 0x8000 ? 0xff : 0;
line[i++] = a;
}
}
png_write_row(png_ptr, line);
}
free(line);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
}
///////////////////////////////////////////////////////////////////////////////////////
#endif
//////////////////////////////////////////////////////////////////////////////////////////