* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#ifdef __WXMSW__
-#include <windows.h>
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/wx.h"
#endif
+#ifdef __WXMSW__
+#include <windows.h>
+#endif
+
#include "lw.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
-#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')
// when using the direct evaluation in the return statement
wxInt32 first = read_char(f) ;
wxInt32 second = read_char(f) ;
-
+
return (first<<8) | second ;
}
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++;
static void read_pols(FILE *f, int nbytes, lwObject *lwo)
{
int guess_cnt = lwo->face_cnt;
-
+
while (nbytes > 0) {
lwFace *face;
int i;
/* allocate space for points */
face->index = (int*) calloc(sizeof(int)*face->index_cnt,1);
-
+
/* read points in */
for (i=0; i<face->index_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;
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;
-int lw_is_lwobject(const char *lw_file)
+bool lw_is_lwobject(const char *lw_file)
{
FILE *f = fopen(lw_file, "rb");
if (f) {
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;
}
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) {
}
/* 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) {
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);
}
}
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 */
}
}
+#endif