shape.c

00001 /*
00002 
00003   Velocity  v1.5
00004   Copyright 2006, 2007 Gabriel Anderson
00005 
00006   This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 */
00021 
00022 //---------------------------------------------------------------------------------//
00023 // Includes                                                                        //
00024 //---------------------------------------------------------------------------------//
00025 
00026 #include "vlib.h"
00027 
00028 //---------------------------------------------------------------------------------//
00029 // Shape                                                                           //
00030 //---------------------------------------------------------------------------------//
00031 
00032 const int POINTS = 0;
00033 const int LINES = 1;
00034 const int LINE_STRIP = 2;
00035 const int TRIANGLES = 3;
00036 const int TRIANGLE_STRIP = 4;
00037 const int TRIANGLE_FAN = 5;
00038 const int SPRITES = 6;
00039 
00040 // Some simple shapes
00041 // Pixel
00042 void draw_point ( float x, float y, u32 color ) {
00043   CP_Vertex_2D* vertices = ( CP_Vertex_2D* ) sceGuGetMemory ( 1 * sizeof ( CP_Vertex_2D ) );
00044 
00045   vertices[0].color = color;
00046   vertices[0].x = x;
00047   vertices[0].y = y;
00048   vertices[0].z = 0;
00049 
00050   sceGuDrawArray ( GU_POINTS, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 1, 0, vertices );
00051 }
00052 
00053 // Lines
00054 void draw_line ( float startX, float startY, float endX, float endY, u32 color ) {
00055   CP_Vertex_2D* vertices = ( CP_Vertex_2D* ) sceGuGetMemory ( 2 * sizeof ( CP_Vertex_2D ) );
00056 
00057   vertices[0].color = color;
00058   vertices[0].x = startX;
00059   vertices[0].y = startY;
00060   vertices[0].z = 0;
00061 
00062   vertices[1].color = color;
00063   vertices[1].x = endX;
00064   vertices[1].y = endY;
00065   vertices[1].z = 0;
00066 
00067   sceGuDrawArray ( GU_LINES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices );
00068 }
00069 
00070 void draw_grad_line ( float startX, float startY, float endX, float endY, u32 color1, u32 color2 ) {
00071   CP_Vertex_2D* vertices = ( CP_Vertex_2D* ) sceGuGetMemory ( 2 * sizeof ( CP_Vertex_2D ) );
00072 
00073   vertices[0].color = color1;
00074   vertices[0].x = startX;
00075   vertices[0].y = startY;
00076   vertices[0].z = 0;
00077 
00078   vertices[1].color = color2;
00079   vertices[1].x = endX;
00080   vertices[1].y = endY;
00081   vertices[1].z = 0;
00082 
00083   sceGuDrawArray ( GU_LINES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices );
00084 }
00085 
00086 // Rectangles
00087 void draw_rect ( float x, float y, float width, float height, u32 color ) {
00088   CP_Vertex_2D* vertices = ( CP_Vertex_2D* ) sceGuGetMemory ( 4 * sizeof ( CP_Vertex_2D ) );
00089 
00090   vertices[0].color = color;
00091   vertices[0].x = x;
00092   vertices[0].y = y;
00093   vertices[0].z = 0;
00094 
00095   vertices[1].color = color;
00096   vertices[1].x = x + width;
00097   vertices[1].y = y;
00098   vertices[1].z = 0;
00099 
00100   vertices[2].color = color;
00101   vertices[2].x = x + width;
00102   vertices[2].y = y + height;
00103   vertices[2].z = 0;
00104 
00105   vertices[3].color = color;
00106   vertices[3].x = x;
00107   vertices[3].y = y + height;
00108   vertices[3].z = 0;
00109 
00110   sceGuDrawArray ( GU_LINE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 4, 0, vertices );
00111 }
00112 
00113 void draw_grad_rect ( float x, float y, float width, float height, u32 color1, u32 color2, u32 color3, u32 color4 ) {
00114   CP_Vertex_2D* vertices = ( CP_Vertex_2D* ) sceGuGetMemory ( 4 * sizeof ( CP_Vertex_2D ) );
00115 
00116   vertices[0].color = color1;
00117   vertices[0].x = x;
00118   vertices[0].y = y;
00119   vertices[0].z = 0;
00120 
00121   vertices[1].color = color2;
00122   vertices[1].x = x + width;
00123   vertices[1].y = y;
00124   vertices[1].z = 0;
00125 
00126   vertices[2].color = color3;
00127   vertices[2].x = x + width;
00128   vertices[2].y = y + height;
00129   vertices[2].z = 0;
00130 
00131   vertices[3].color = color4;
00132   vertices[3].x = x;
00133   vertices[3].y = y + height;
00134   vertices[3].z = 0;
00135 
00136   sceGuDrawArray ( GU_LINE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 4, 0, vertices );
00137 }
00138 
00139 void draw_fill_rect ( float x, float y, float width, float height, u32 color ) {
00140   CP_Vertex_2D* vertices = ( CP_Vertex_2D* ) sceGuGetMemory ( 2 * sizeof ( CP_Vertex_2D ) );
00141 
00142   vertices[0].color = color;
00143   vertices[0].x = x;
00144   vertices[0].y = y;
00145   vertices[0].z = 0;
00146 
00147   vertices[1].color = color;
00148   vertices[1].x = x + width;
00149   vertices[1].y = y + width;
00150   vertices[1].z = 0;
00151 
00152   sceGuDrawArray ( GU_SPRITES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices );
00153 }
00154 
00155 void draw_fill_grad_rect ( float x, float y, float width, float height, u32 color1, u32 color2, u32 color3, u32 color4 ) {
00156   CP_Vertex_2D* vertices = ( CP_Vertex_2D* ) sceGuGetMemory ( 4 * sizeof ( CP_Vertex_2D ) );
00157 
00158   vertices[0].color = color1;
00159   vertices[0].x = x;
00160   vertices[0].y = y;
00161   vertices[0].z = 0;
00162 
00163   vertices[1].color = color2;
00164   vertices[1].x = x + width;
00165   vertices[1].y = y;
00166   vertices[1].z = 0;
00167 
00168   vertices[2].color = color3;
00169   vertices[2].x = x;
00170   vertices[2].y = y + height;
00171   vertices[2].z = 0;
00172 
00173   vertices[3].color = color4;
00174   vertices[3].x = x + width;
00175   vertices[3].y = y + height;
00176   vertices[3].z = 0;
00177 
00178   sceGuDrawArray ( GU_TRIANGLE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 4, 0, vertices );
00179 }

Generated on Tue Mar 20 23:01:06 2007 for vLib by  doxygen 1.4.7