TARGET = laz0r
-OBJS = main.o game.o gfx.o model.o
+OBJS = main.o game.o gfx.o model.o texture.o
PSP_FW_VERSION=401
BUILD_PRX=1
#include "game.h"
#include "gfx.h"
#include "model.h"
+#include "texture.h"
#include <pspgu.h>
#include <pspgum.h>
GFX.init();
//Model cube("colors-noUV.lob");
- Model cube("models/colors-noUV.lob");
+ Model cube("models/ship.lob");
+ Texture texture("models/ship.tga");
//sceKernelDcacheWritebackRange(cube.vertices, cube.num_vertices * sizeof(Vertex));
//sceKernelDcacheWritebackRange(cube.indices, cube.num_faces * sizeof(unsigned short));
//sceKernelDcacheWritebackRange(&cube, sizeof(cube));
sceGumRotateY(0.001f*i);
sceGumRotateZ(0.001f*i);
sceGuColor(GU_COLOR(1.0f,1.0f,1.0f,0.0f));
+ sceGuTexImage( 0, texture.width, texture.height, texture.width, texture.pixels );
sceGumDrawArray(GU_TRIANGLES,
- /*GU_TEXTURE_32BITF |*/ GU_COLOR_8888 | GU_NORMAL_32BITF |
+ GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_NORMAL_32BITF |
GU_VERTEX_32BITF | GU_TRANSFORM_3D | GU_INDEX_16BIT, cube.num_faces*3,
cube.indices, cube.vertices);
- ScePspFVector3 move={2,0,0};
+ ScePspFVector3 move={4,0,0};
sceGumLoadIdentity();
sceGumRotateZ(0.001f*i);
sceGumTranslate(&move);
void Gfx::init()
{
- display_list = memalign(16, 2048);
+ display_list = memalign(16, 8192);
fbp0 = 0;
pspDebugScreenInit();
sceGuEnable( GU_DEPTH_TEST );
sceGuShadeModel( GU_SMOOTH );
sceGuFrontFace( GU_CW );
- sceGuEnable( GU_CULL_FACE );
- sceGuEnable( GU_CLIP_PLANES );
+ //sceGuEnable( GU_CULL_FACE );
+ //sceGuEnable( GU_CLIP_PLANES );
// set clear color/depth
- sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) );
+ sceGuClearColor( GU_COLOR( 1.0f, 0.0f, 1.0f, 1.0f ) );
sceGuClearDepth(0);
- sceGuFinish();
+ // setup texture
+ sceGuEnable(GU_TEXTURE_2D); //Enable Texture2D
+ sceGuTexMode( GU_PSM_8888, 0, 0, 0 ); // last 0 must be 1 if swizzled
+ sceGuTexFunc( GU_TFX_DECAL, GU_TCC_RGB );
+ sceGuTexFilter( GU_LINEAR, GU_LINEAR ); // Linear filtering (Good Quality) (NEW)
+ sceGuTexScale( 1.0f, 1.0f ); // No scaling
+ sceGuTexOffset( 0.0f, 0.0f );
+
+ sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
+PSP_HEAP_SIZE_MAX();
+
// Exit callback
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
#include <cstdio>
#include <cstring>
+inline bool isnan(float x)
+{
+ return x!=x;
+}
+
struct ModelHeader
{
char sig[8]; // "laz0rOBJ"
fread(vertices, sizeof(Vertex), num_vertices, f);
fread(indices, sizeof(unsigned short), 3*num_faces, f);
fclose(f);
+
+ for (int i=0; i<num_vertices; i++)
+ {
+ if (isnan(vertices[i].u) || isnan(vertices[i].v))
+ printf("NaN!\n");
+ }
+
+ printf("%d vertices, %d faces\n", num_vertices, num_faces);
}
Model::~Model()
struct Vertex
{
- //float u,v;
+ float u,v;
u32 color;
float nx,ny,nz;
float x,y,z;
--- /dev/null
+#include "texture.h"
+
+#include <cstdio>
+#include <cstring>
+
+Texture::Texture(const char *filename)
+{
+ FILE *pFile = 0;
+
+ // Variables to hold image info
+ unsigned char tempColor;
+ unsigned char bitCount;
+ int colorMode;
+ long tgaSize;
+ unsigned char unCompressHeader[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ unsigned char tgaHeader[12];
+ unsigned char header[6];
+
+ swizzled=false;
+
+ // Open file
+ pFile = fopen( filename, "rb" );
+
+ if( !pFile ) {
+ // if couldn't open, exit
+ return;
+ }
+
+ // Read in BitmapHeader info into the structure
+ fread( &tgaHeader, 1, sizeof(tgaHeader), pFile );
+
+ // We only want to read uncompressed TGA's. Chech the
+ // header if it is of an uncompressed one.
+ if( memcmp( unCompressHeader, tgaHeader, sizeof(unCompressHeader)) != 0 ) {
+ fclose( pFile );
+ printf("Error, not an uncompressed TGA file\n");
+ width=0;
+ height=0;
+ pixels=0;
+ return;
+ }
+
+ // Read Image info
+ fread( header, 1, sizeof(header), pFile );
+
+ // Calculate and save the Width & Height of Image
+ width = header[1] * 256 + header[0];
+ height = header[3] * 256 + header[2];
+ bitCount = header[4];
+
+ // Calculate color mode & image size
+ colorMode = bitCount / 8;
+ tgaSize = width * height * colorMode;
+ printf("width=%hd, height=%hd, tgaSize=%ld\n", width, height, tgaSize);
+
+ // Allocate memory for the image and load it
+ pixels = new unsigned char[tgaSize];
+
+ fread( pixels, sizeof(unsigned char), tgaSize, pFile );
+
+ // Convert from BGR to RGB format.
+ for(long index = 0; index < tgaSize; index += colorMode) {
+ tempColor = pixels[index];
+ pixels[index] = pixels[index + 2];
+ pixels[index + 2] = tempColor;
+ }
+
+ // Close the file
+ fclose( pFile );
+
+ printf("Read TGA texture %s (%ux%u)\n", filename, width, height);
+
+ return;
+}
+
+Texture::~Texture()
+{
+ delete[] pixels;
+}
+
+void swizzle()
+{
+
+}
+
+
+
+
--- /dev/null
+#if !defined(TEXTURE_H)
+#define TEXTURE_H
+
+struct Texture
+{
+ unsigned short width;
+ unsigned short height;
+ unsigned char *pixels;
+ bool swizzled;
+
+ Texture(const char *filename);
+ ~Texture();
+
+ void swizzle();
+};
+
+#endif
+
if mesh.faceUV:
u,v=face.uv[vert_i]
+ print "(u,v)=(%f,%f)"%(u,v)
else:
u,v=0,0
index_list.append(matching_index)
#print matching_index
- #print "end face"
+ print "end face"
# write header
f = file(filename, "w")
r,g,b,a = vert["col"]
nx,ny,nz = vert["no"]
x,y,z = vert["co"]
- #f.write(struct.pack("< ff BBBB fff fff", u,v, r,g,b,a, nx, ny, nz, x,y,z)) # 36 bytes each
- f.write(struct.pack("< BBBB fff fff", r,g,b,a, nx, ny, nz, x,y,z)) # 36 bytes each
+ f.write(struct.pack("< ff BBBB fff fff", u,v, r,g,b,a, nx, ny, nz, x,y,z)) # 36 bytes each
+ #f.write(struct.pack("< BBBB fff fff", r,g,b,a, nx, ny, nz, x,y,z)) # 28 bytes each
for i in index_list:
f.write(struct.pack("<H", i))