X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/56cfd0d766b3240ef34157eb1669ffd9e2a86b9b..6ba5438dda164146bf36ca729f8328332fae36b7:/samples/opengl/penguin/lw.cpp?ds=sidebyside diff --git a/samples/opengl/penguin/lw.cpp b/samples/opengl/penguin/lw.cpp index aaa1d889c2..9b2202000c 100644 --- a/samples/opengl/penguin/lw.cpp +++ b/samples/opengl/penguin/lw.cpp @@ -16,10 +16,6 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef __WXMSW__ -#include -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -31,23 +27,20 @@ #include "wx/wx.h" #endif +#ifdef __WXMSW__ +#include +#endif + #include "lw.h" #include #include -#include - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif +#if wxUSE_GLCANVAS #define MK_ID(a,b,c,d) ((((wxUint32)(a))<<24)| \ - (((wxUint32)(b))<<16)| \ - (((wxUint32)(c))<< 8)| \ - (((wxUint32)(d)) )) + (((wxUint32)(b))<<16)| \ + (((wxUint32)(c))<< 8)| \ + (((wxUint32)(d)) )) #define ID_FORM MK_ID('F','O','R','M') #define ID_LWOB MK_ID('L','W','O','B') @@ -69,7 +62,7 @@ static wxInt32 read_short(FILE *f) // when using the direct evaluation in the return statement wxInt32 first = read_char(f) ; wxInt32 second = read_char(f) ; - + return (first<<8) | second ; } @@ -97,7 +90,7 @@ static int read_string(FILE *f, char *s) do { c = read_char(f); if (cnt < LW_MAX_NAME_LEN) - s[cnt] = c; + s[cnt] = (char)c; else s[LW_MAX_NAME_LEN-1] = 0; cnt++; @@ -128,9 +121,9 @@ static void read_srfs(FILE *f, int nbytes, lwObject *lwo) nbytes -= read_string(f,material->name); /* defaults */ - material->r = 0.7; - material->g = 0.7; - material->b = 0.7; + material->r = 0.7f; + material->g = 0.7f; + material->b = 0.7f; } lwo->material = (lwMaterial*) realloc(lwo->material, sizeof(lwMaterial)*lwo->material_cnt); } @@ -176,7 +169,7 @@ static void read_surf(FILE *f, int nbytes, lwObject *lwo) static void read_pols(FILE *f, int nbytes, lwObject *lwo) { int guess_cnt = lwo->face_cnt; - + while (nbytes > 0) { lwFace *face; int i; @@ -194,17 +187,17 @@ static void read_pols(FILE *f, int nbytes, lwObject *lwo) /* allocate space for points */ face->index = (int*) calloc(sizeof(int)*face->index_cnt,1); - + /* read points in */ for (i=0; iindex_cnt; i++) { face->index[i] = read_short(f); nbytes -= 2; } - + /* read surface material */ face->material = read_short(f); nbytes -= 2; - + /* skip over detail polygons */ if (face->material < 0) { int det_cnt; @@ -212,9 +205,9 @@ static void read_pols(FILE *f, int nbytes, lwObject *lwo) det_cnt = read_short(f); nbytes -= 2; while (det_cnt-- > 0) { - int cnt = read_short(f); - fseek(f, cnt*2+2, SEEK_CUR); - nbytes -= cnt*2+2; + int cnt = read_short(f); + fseek(f, cnt*2+2, SEEK_CUR); + nbytes -= cnt*2+2; } } face->material -= 1; @@ -242,7 +235,7 @@ static void read_pnts(FILE *f, int nbytes, lwObject *lwo) -int lw_is_lwobject(const char *lw_file) +bool lw_is_lwobject(const char *lw_file) { FILE *f = fopen(lw_file, "rb"); if (f) { @@ -251,22 +244,17 @@ int lw_is_lwobject(const char *lw_file) wxInt32 lwob = read_long(f); fclose(f); if (form == ID_FORM && nlen != 0 && lwob == ID_LWOB) - return TRUE; + return true; } - return FALSE; + return false; } lwObject *lw_object_read(const char *lw_file) { - FILE *f = NULL; - lwObject *lw_object = NULL; - - wxInt32 form_bytes = 0; - wxInt32 read_bytes = 0; /* open file */ - f = fopen(lw_file, "rb"); + FILE *f = fopen(lw_file, "rb"); if (f == NULL) { return NULL; } @@ -276,7 +264,10 @@ lwObject *lw_object_read(const char *lw_file) fclose(f); return NULL; } - form_bytes = read_long(f); + + wxInt32 read_bytes = 0; + + wxInt32 form_bytes = read_long(f); read_bytes += 4; if (read_long(f) != ID_LWOB) { @@ -285,7 +276,7 @@ lwObject *lw_object_read(const char *lw_file) } /* create new lwObject */ - lw_object = (lwObject*) calloc(sizeof(lwObject),1); + lwObject *lw_object = (lwObject*) calloc(sizeof(lwObject),1); /* read chunks */ while (read_bytes < form_bytes) { @@ -380,13 +371,13 @@ void lw_object_show(const lwObject *lw_object) prev_index_cnt = face->index_cnt; switch (face->index_cnt) { case 3: - glBegin(GL_TRIANGLES); - break; + glBegin(GL_TRIANGLES); + break; case 4: - glBegin(GL_QUADS); - break; + glBegin(GL_QUADS); + break; default: - glBegin(GL_POLYGON); + glBegin(GL_POLYGON); } } @@ -394,8 +385,8 @@ void lw_object_show(const lwObject *lw_object) if (prev_material != face->material) { prev_material = face->material; glColor3f(lw_object->material[face->material].r, - lw_object->material[face->material].g, - lw_object->material[face->material].b); + lw_object->material[face->material].g, + lw_object->material[face->material].b); } /* update normal if necessary */ @@ -443,4 +434,5 @@ void lw_object_scale(lwObject *lwo, GLfloat scale) } } +#endif