// // Book: OpenGL(R) ES 2.0 Programming Guide // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner // ISBN-10: 0321502795 // ISBN-13: 9780321502797 // Publisher: Addison-Wesley Professional // URLs: http://safari.informit.com/9780321563835 // http://www.opengles-book.com // // ESUtil.c // // A utility library for OpenGL ES. This library provides a // basic common framework for the example applications in the // OpenGL ES 2.0 Programming Guide. // /// // Includes // #include #include #include #include #include #include "esUtil.h" /// // esLogMessage() // // Log an error message to the debug output for the platform // void ESUTIL_API esLogMessage ( const char *formatStr, ... ) { va_list params; char buf[BUFSIZ]; va_start ( params, formatStr ); vsprintf ( buf, formatStr, params ); printf ( "%s", buf ); va_end ( params ); } /// // esLoadTGA() // // Loads a 24-bit TGA image from a file. This is probably the simplest TGA loader ever. // Does not support loading of compressed TGAs nor TGAa with alpha channel. But for the // sake of the examples, this is sufficient. // char* ESUTIL_API esLoadTGA ( char *fileName, int *width, int *height ) { char *buffer = NULL; FILE *f; unsigned char tgaheader[12]; unsigned char attributes[6]; unsigned int imagesize; f = fopen(fileName, "rb"); if(f == NULL) return NULL; if(fread(&tgaheader, sizeof(tgaheader), 1, f) == 0) { fclose(f); return NULL; } if(fread(attributes, sizeof(attributes), 1, f) == 0) { fclose(f); return 0; } *width = attributes[1] * 256 + attributes[0]; *height = attributes[3] * 256 + attributes[2]; imagesize = attributes[4] / 8 * *width * *height; buffer = malloc(imagesize); if (buffer == NULL) { fclose(f); return 0; } if(fread(buffer, 1, imagesize, f) != imagesize) { free(buffer); return NULL; } fclose(f); return buffer; } double esNow(void) { struct timeval tv; #ifdef __VMS (void) gettimeofday(&tv, NULL ); #else (void) gettimeofday(&tv, NULL); #endif return tv.tv_sec * 1.0 + tv.tv_usec / 1000000.0; }