From 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 Mon Sep 17 00:00:00 2001 From: git perforce import user Date: Tue, 25 Oct 2016 12:29:14 -0600 Subject: Initial commit: PhysX 3.4.0 Update @ 21294896 APEX 1.4.0 Update @ 21275617 [CL 21300167] --- KaplaDemo/samples/sampleViewer3/Texture.cpp | 283 ++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 KaplaDemo/samples/sampleViewer3/Texture.cpp (limited to 'KaplaDemo/samples/sampleViewer3/Texture.cpp') diff --git a/KaplaDemo/samples/sampleViewer3/Texture.cpp b/KaplaDemo/samples/sampleViewer3/Texture.cpp new file mode 100644 index 00000000..9f99e439 --- /dev/null +++ b/KaplaDemo/samples/sampleViewer3/Texture.cpp @@ -0,0 +1,283 @@ +#include +#include +#include +#include "BmpFile.h" +#include +#include "IJGWin32/CPPJPEGWrapper.h" +#include "TgaFile.h" +using namespace std; +// standard cubemap face names +/* +const char *faceName[6] = { + "negz", + "negz", + "posy", + "negy", + "negz", + "negz", +}; +*/ +const char *faceName0[6] = { + "posx", + "negx", + "posy", + "negy", + "posz", + "negz", +}; +const char *faceName1[6] = { + "ft", + "bk", + "up", + "dn", + "rt", + "lf", +}; + + +void loadImg(GLenum target, const char *filename, char mode = 0, float sr = 0.0f, float sg = 0.0f, float sb = 0.0f, float startGrad = -1.0f, float endGrad = -1.0f, char dir = 1) +{ + int len = strlen(filename); + + unsigned char* ptr = 0, *ptrBegin; + int w, h; + + BmpLoaderBuffer loader; + CPPJPEGWrapper jpg; + TGAFILE tgafile; + tga_image* image = new tga_image(); + + if (strcmp(&filename[len-4], ".jpg") == 0) + { + // jpg + if (!jpg.LoadJPEG(filename, false)) { + printf("Error load jpg %s\n", filename); + return; + } + h = jpg.GetHeight(); + w = jpg.GetWidth(); + ptrBegin = ptr = jpg.GetData(); + } + else if (strcmp(&filename[len-4], ".bmp") == 0) + { + // bmp + if (!loader.loadFile(filename)) { + fprintf(stderr, "Error loading bmp '%s'\n"); + return; + } + ptrBegin = ptr = loader.mRGB; + h = loader.mHeight; + w = loader.mWidth; + + } + else + { + //tga + + FILE *file = fopen(filename, "rb"); + if (file == NULL) + { + fprintf(stderr, "Error loading tga '%s'\n"); + return; + } + bool ok = (TGA_NOERR == tga_read_from_FILE(image, file)); + + //// flip it to make it look correct in the SampleFramework's renderer + //tga_flip_vert(image); + + if (!ok) + { + fprintf(stderr, "Error loading tga '%s'\n"); + return; + } + + /*if (!LoadTGAFile(filename, &tgafile)) + { + fprintf(stderr, "Error loading tga '%s'\n"); + return; + }*/ + + ptrBegin = ptr = image->image_data; + h = image->height; + w = image->width; + + fclose(file); + + } +/*{GLenum er = glGetError(); if (er != GL_NO_ERROR) { cout<<"Var name: "<