From be2a4ee4ec2148798ff3d3c3699cfba4907ff5b3 Mon Sep 17 00:00:00 2001 From: "wrenczes@gmail.com" Date: Sun, 24 Apr 2011 10:00:37 +0000 Subject: [PATCH] Mostly formatting cleanup, but a couple of openGL related fixes : don't call state change functions if their params haven't changed. In particular, we call ClearScreen() in several places in the code, but BeginScene() already does this. According to several openGL performance guides I skimmed through, if you call clear more than once per frame draw, performance will suffer. This seems to help with issue r103 - on my win machine, it's substantially better; on psp, not quite as drastic, but it's still better than before. --- JGE/src/JGfx.cpp | 11 +- JGE/src/main.cpp | 407 ++-- JGE/src/pc/JGfx.cpp | 4443 ++++++++++++++++++++++--------------------- 3 files changed, 2441 insertions(+), 2420 deletions(-) diff --git a/JGE/src/JGfx.cpp b/JGE/src/JGfx.cpp index 8297426db..3896ebf97 100644 --- a/JGE/src/JGfx.cpp +++ b/JGE/src/JGfx.cpp @@ -362,10 +362,13 @@ void JRenderer::EnableVSync(bool flag) void JRenderer::ClearScreen(PIXEL_TYPE color) { - sceGuClearColor(color); - //sceGuClearStencil( 0 ); - sceGuClear(GU_COLOR_BUFFER_BIT); - //sceGuClear( GU_COLOR_BUFFER_BIT | GU_STENCIL_BUFFER_BIT ); + static PIXEL_TYPE previousColor = 0xFFFFFFFF; + if (previousColor != color) + { + sceGuClearColor(color); + sceGuClear(GU_COLOR_BUFFER_BIT); + previousColor = color; + } } diff --git a/JGE/src/main.cpp b/JGE/src/main.cpp index 909a2b4a2..426677771 100644 --- a/JGE/src/main.cpp +++ b/JGE/src/main.cpp @@ -29,16 +29,16 @@ #ifdef DEVHOOK - PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1); - PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); - //256 is not enough for the network to correctly start, - // let's find an appropriate value the day JGE has working network - PSP_HEAP_SIZE_KB(-256); +PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1); +PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); +//256 is not enough for the network to correctly start, +// let's find an appropriate value the day JGE has working network +PSP_HEAP_SIZE_KB(-256); #else - PSP_MODULE_INFO(JGEApp_Title, 0x1000, 1, 1); - PSP_MAIN_THREAD_ATTR(0); +PSP_MODULE_INFO(JGEApp_Title, 0x1000, 1, 1); +PSP_MAIN_THREAD_ATTR(0); #endif @@ -55,57 +55,57 @@ u32 gTickFrequency; // Exit callback int exit_callback(int arg1, int arg2, void *common) { - if (g_engine != NULL) - g_engine->End(); - sceKernelExitGame(); - return 0; + if (g_engine != NULL) + g_engine->End(); + sceKernelExitGame(); + return 0; } //------------------------------------------------------------------------------------------------ // Power Callback int power_callback(int unknown, int pwrflags, void *common) { - if ((pwrflags & (PSP_POWER_CB_POWER_SWITCH | PSP_POWER_CB_STANDBY)) > 0) + if ((pwrflags & (PSP_POWER_CB_POWER_SWITCH | PSP_POWER_CB_STANDBY)) > 0) { - // suspending - if (g_engine != NULL) g_engine->Pause(); + // suspending + if (g_engine != NULL) g_engine->Pause(); } - else if ((pwrflags & PSP_POWER_CB_RESUME_COMPLETE) > 0) + else if ((pwrflags & PSP_POWER_CB_RESUME_COMPLETE) > 0) { - sceKernelDelayThread(1500000); - // resume complete - if (g_engine != NULL) - g_engine->Resume(); + sceKernelDelayThread(1500000); + // resume complete + if (g_engine != NULL) + g_engine->Resume(); } - return 0; + return 0; } //------------------------------------------------------------------------------------------------ // Callback thread int CallbackThread(SceSize args, void *argp) { - int cbid; + int cbid; #ifdef DEVHOOK - cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); - sceKernelRegisterExitCallback(cbid); + cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); + sceKernelRegisterExitCallback(cbid); #endif - cbid = sceKernelCreateCallback("Power Callback", power_callback, NULL); - scePowerRegisterCallback(0, cbid); + cbid = sceKernelCreateCallback("Power Callback", power_callback, NULL); + scePowerRegisterCallback(0, cbid); - sceKernelSleepThreadCB(); + sceKernelSleepThreadCB(); - return 0; + return 0; } // Sets up the callback thread and returns its thread id int SetupCallbacks(void) { - int thid = 0; + int thid = 0; - thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); - if (thid >= 0) sceKernelStartThread(thid, 0, 0); - return thid; + thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); + if (thid >= 0) sceKernelStartThread(thid, 0, 0); + return thid; } @@ -139,81 +139,81 @@ static const unsigned char regName[32][5] = void ExceptionHandler(PspDebugRegBlock * regs) { - int i; - SceCtrlData pad; + int i; + SceCtrlData pad; - pspDebugScreenInit(); - pspDebugScreenSetBackColor(0x00FF0000); - pspDebugScreenSetTextColor(0xFFFFFFFF); - pspDebugScreenClear(); - pspDebugScreenPrintf("Your PSP has just crashed!\n"); - pspDebugScreenPrintf("Exception details:\n\n"); + pspDebugScreenInit(); + pspDebugScreenSetBackColor(0x00FF0000); + pspDebugScreenSetTextColor(0xFFFFFFFF); + pspDebugScreenClear(); + pspDebugScreenPrintf("Your PSP has just crashed!\n"); + pspDebugScreenPrintf("Exception details:\n\n"); - pspDebugScreenPrintf("Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); - pspDebugScreenPrintf("EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); - pspDebugScreenPrintf("Cause - %08X\n", (int)regs->cause); - pspDebugScreenPrintf("Status - %08X\n", (int)regs->status); - pspDebugScreenPrintf("BadVAddr - %08X\n", (int)regs->badvaddr); - for (i = 0; i < 32; i += 4) pspDebugScreenPrintf("%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); + pspDebugScreenPrintf("Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); + pspDebugScreenPrintf("EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); + pspDebugScreenPrintf("Cause - %08X\n", (int)regs->cause); + pspDebugScreenPrintf("Status - %08X\n", (int)regs->status); + pspDebugScreenPrintf("BadVAddr - %08X\n", (int)regs->badvaddr); + for (i = 0; i < 32; i += 4) pspDebugScreenPrintf("%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); - sceKernelDelayThread(1000000); - pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit"); - pspDebugScreenPrintf("\nPress O to quit"); + sceKernelDelayThread(1000000); + pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit"); + pspDebugScreenPrintf("\nPress O to quit"); - for (;;) + for (;;) { - sceCtrlReadBufferPositive(&pad, 1); - if (pad.Buttons & PSP_CTRL_CROSS) + sceCtrlReadBufferPositive(&pad, 1); + if (pad.Buttons & PSP_CTRL_CROSS) { - FILE *log = fopen("exception.log", "w"); - if (log != NULL) + FILE *log = fopen("exception.log", "w"); + if (log != NULL) { - char testo[512]; - sprintf(testo, "Exception details:\n\n"); - fwrite(testo, 1, strlen(testo), log); - sprintf(testo, "Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); - fwrite(testo, 1, strlen(testo), log); - sprintf(testo, "EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); - fwrite(testo, 1, strlen(testo), log); - sprintf(testo, "Cause - %08X\n", (int)regs->cause); - fwrite(testo, 1, strlen(testo), log); - sprintf(testo, "Status - %08X\n", (int)regs->status); - fwrite(testo, 1, strlen(testo), log); - sprintf(testo, "BadVAddr - %08X\n", (int)regs->badvaddr); - fwrite(testo, 1, strlen(testo), log); - for (i = 0; i < 32; i += 4) + char testo[512]; + sprintf(testo, "Exception details:\n\n"); + fwrite(testo, 1, strlen(testo), log); + sprintf(testo, "Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); + fwrite(testo, 1, strlen(testo), log); + sprintf(testo, "EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); + fwrite(testo, 1, strlen(testo), log); + sprintf(testo, "Cause - %08X\n", (int)regs->cause); + fwrite(testo, 1, strlen(testo), log); + sprintf(testo, "Status - %08X\n", (int)regs->status); + fwrite(testo, 1, strlen(testo), log); + sprintf(testo, "BadVAddr - %08X\n", (int)regs->badvaddr); + fwrite(testo, 1, strlen(testo), log); + for (i = 0; i < 32; i += 4) { - sprintf(testo, "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); - fwrite(testo, 1, strlen(testo), log); + sprintf(testo, "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); + fwrite(testo, 1, strlen(testo), log); } - fclose(log); + fclose(log); } - break; + break; } - else if (pad.Buttons & PSP_CTRL_CIRCLE) - break; - sceKernelDelayThread(100000); + else if (pad.Buttons & PSP_CTRL_CIRCLE) + break; + sceKernelDelayThread(100000); } - sceKernelExitGame(); + sceKernelExitGame(); } void initExceptionHandler() { - SceKernelLMOption option; - int args[2], fd, modid; + SceKernelLMOption option; + int args[2], fd, modid; - memset(&option, 0, sizeof(option)); - option.size = sizeof(option); - option.mpidtext = PSP_MEMORY_PARTITION_KERNEL; - option.mpiddata = PSP_MEMORY_PARTITION_KERNEL; - option.position = 0; - option.access = 1; + memset(&option, 0, sizeof(option)); + option.size = sizeof(option); + option.mpidtext = PSP_MEMORY_PARTITION_KERNEL; + option.mpiddata = PSP_MEMORY_PARTITION_KERNEL; + option.position = 0; + option.access = 1; - if ((modid = sceKernelLoadModule("exception.prx", 0, &option)) >= 0) + if ((modid = sceKernelLoadModule("exception.prx", 0, &option)) >= 0) { - args[0] = (int)ExceptionHandler; - args[1] = (int)&exception_regs; - sceKernelStartModule(modid, 8, args, &fd, NULL); + args[0] = (int)ExceptionHandler; + args[1] = (int)&exception_regs; + sceKernelStartModule(modid, 8, args, &fd, NULL); } } #else @@ -221,38 +221,38 @@ void initExceptionHandler() // Custom exception handler void MyExceptionHandler(PspDebugRegBlock *regs) { - pspDebugScreenInit(); + pspDebugScreenInit(); - pspDebugScreenSetBackColor(0x00FF0000); - pspDebugScreenSetTextColor(0xFFFFFFFF); - pspDebugScreenClear(); + pspDebugScreenSetBackColor(0x00FF0000); + pspDebugScreenSetTextColor(0xFFFFFFFF); + pspDebugScreenClear(); - pspDebugScreenPrintf("I regret to inform you your psp has just crashed\n"); - pspDebugScreenPrintf("Please contact Sony technical support for further information\n\n"); - pspDebugScreenPrintf("Exception Details:\n"); - pspDebugDumpException(regs); - pspDebugScreenPrintf("\nBlame the 3rd party software, it cannot possibly be our fault!\n"); + pspDebugScreenPrintf("I regret to inform you your psp has just crashed\n"); + pspDebugScreenPrintf("Please contact Sony technical support for further information\n\n"); + pspDebugScreenPrintf("Exception Details:\n"); + pspDebugDumpException(regs); + pspDebugScreenPrintf("\nBlame the 3rd party software, it cannot possibly be our fault!\n"); - sceKernelExitGame(); + sceKernelExitGame(); } //------------------------------------------------------------------------------------------------ // Sort of hack to install exception handler under USER THREAD __attribute__((constructor)) void handlerInit() { - pspKernelSetKernelPC(); + pspKernelSetKernelPC(); - pspSdkInstallNoDeviceCheckPatch(); - pspSdkInstallNoPlainModuleCheckPatch(); - pspSdkInstallKernelLoadModulePatch(); + pspSdkInstallNoDeviceCheckPatch(); + pspSdkInstallNoPlainModuleCheckPatch(); + pspSdkInstallKernelLoadModulePatch(); - pspDebugInstallErrorHandler(MyExceptionHandler); + pspDebugInstallErrorHandler(MyExceptionHandler); } #endif static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] = - { +{ { PSP_CTRL_START, JGE_BTN_MENU }, { PSP_CTRL_SELECT, JGE_BTN_CTRL }, { PSP_CTRL_RIGHT, JGE_BTN_RIGHT }, @@ -265,17 +265,19 @@ static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] { PSP_CTRL_CROSS, JGE_BTN_SEC }, { PSP_CTRL_LTRIGGER, JGE_BTN_PREV }, { PSP_CTRL_RTRIGGER, JGE_BTN_NEXT } - }; +}; + void JGECreateDefaultBindings() { - for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) - g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode); + for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) + g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode); } + int JGEGetTime() { - u64 curr; - sceRtcGetCurrentTick(&curr); - return (int)((curr * 1000) / gTickFrequency); + u64 curr; + sceRtcGetCurrentTick(&curr); + return (int)((curr * 1000) / gTickFrequency); } static SceCtrlData gCtrlPad; @@ -285,75 +287,76 @@ u8 JGEGetAnalogY() { return gCtrlPad.Ly; } void Run() { - static const int keyCodeList[] = { - PSP_CTRL_SELECT, // Select button. - PSP_CTRL_START, // Start button. - PSP_CTRL_UP, // Up D-Pad button. - PSP_CTRL_RIGHT, // Right D-Pad button. - PSP_CTRL_DOWN, // Down D-Pad button. - PSP_CTRL_LEFT, // Left D-Pad button. - PSP_CTRL_LTRIGGER, // Left trigger. - PSP_CTRL_RTRIGGER, // Right trigger. - PSP_CTRL_TRIANGLE, // Triangle button. - PSP_CTRL_CIRCLE, // Circle button. - PSP_CTRL_CROSS, // Cross button. - PSP_CTRL_SQUARE, // Square button. - PSP_CTRL_HOLD, // Hold button. - /* Do not test keys we cannot get anyway, that's just wasted proc time - PSP_CTRL_HOME, // Home button. - PSP_CTRL_NOTE, // Music Note button. - PSP_CTRL_SCREEN, // Screen button. - PSP_CTRL_VOLUP, // Volume up button. - PSP_CTRL_VOLDOWN, // Volume down button. - PSP_CTRL_WLAN, // _UP Wlan switch up. - PSP_CTRL_REMOTE, // Remote hold position. - PSP_CTRL_DISC, // Disc present. - PSP_CTRL_MS // Memory stick present. - */ - }; - - u64 curr; - long long int nextInput = 0; - u64 lastTime; - u32 oldButtons; - u32 veryOldButtons; - - sceRtcGetCurrentTick(&lastTime); - oldButtons = veryOldButtons = 0; - JGECreateDefaultBindings(); - - while (!g_engine->mDone) + static const int keyCodeList[] = { - sceRtcGetCurrentTick(&curr); - float dt = (curr - lastTime) / (float)gTickFrequency; - g_engine->mDeltaTime = dt; - if (!g_engine->mPaused) - { - sceCtrlPeekBufferPositive(&gCtrlPad, 1); - for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i) - if (keyCodeList[i] & gCtrlPad.Buttons) - { - if (!(keyCodeList[i] & oldButtons)) - g_engine->HoldKey(keyCodeList[i]); - } - else - if (keyCodeList[i] & oldButtons) - g_engine->ReleaseKey(keyCodeList[i]); + PSP_CTRL_SELECT, // Select button. + PSP_CTRL_START, // Start button. + PSP_CTRL_UP, // Up D-Pad button. + PSP_CTRL_RIGHT, // Right D-Pad button. + PSP_CTRL_DOWN, // Down D-Pad button. + PSP_CTRL_LEFT, // Left D-Pad button. + PSP_CTRL_LTRIGGER, // Left trigger. + PSP_CTRL_RTRIGGER, // Right trigger. + PSP_CTRL_TRIANGLE, // Triangle button. + PSP_CTRL_CIRCLE, // Circle button. + PSP_CTRL_CROSS, // Cross button. + PSP_CTRL_SQUARE, // Square button. + PSP_CTRL_HOLD, // Hold button. + /* Do not test keys we cannot get anyway, that's just wasted proc time + PSP_CTRL_HOME, // Home button. + PSP_CTRL_NOTE, // Music Note button. + PSP_CTRL_SCREEN, // Screen button. + PSP_CTRL_VOLUP, // Volume up button. + PSP_CTRL_VOLDOWN, // Volume down button. + PSP_CTRL_WLAN, // _UP Wlan switch up. + PSP_CTRL_REMOTE, // Remote hold position. + PSP_CTRL_DISC, // Disc present. + PSP_CTRL_MS // Memory stick present. + */ + }; - oldButtons = gCtrlPad.Buttons; - g_engine->Update(dt); - g_engine->Render(); + u64 curr; + long long int nextInput = 0; + u64 lastTime; + u32 oldButtons; + u32 veryOldButtons; - if (g_engine->mDebug && strlen(g_engine->mDebuggingMsg) > 0) + sceRtcGetCurrentTick(&lastTime); + oldButtons = veryOldButtons = 0; + JGECreateDefaultBindings(); + + while (!g_engine->mDone) + { + sceRtcGetCurrentTick(&curr); + float dt = (curr - lastTime) / (float)gTickFrequency; + g_engine->mDeltaTime = dt; + if (!g_engine->mPaused) + { + sceCtrlPeekBufferPositive(&gCtrlPad, 1); + for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i) + if (keyCodeList[i] & gCtrlPad.Buttons) + { + if (!(keyCodeList[i] & oldButtons)) + g_engine->HoldKey(keyCodeList[i]); + } + else + if (keyCodeList[i] & oldButtons) + g_engine->ReleaseKey(keyCodeList[i]); + + oldButtons = gCtrlPad.Buttons; + g_engine->Update(dt); + g_engine->Render(); + + if (g_engine->mDebug && strlen(g_engine->mDebuggingMsg) > 0) { - pspDebugScreenSetXY(0, 0); - pspDebugScreenPrintf(g_engine->mDebuggingMsg); + pspDebugScreenSetXY(0, 0); + pspDebugScreenPrintf(g_engine->mDebuggingMsg); } - veryOldButtons = gCtrlPad.Buttons; + veryOldButtons = gCtrlPad.Buttons; } - else - sceKernelDelayThread(1); - lastTime = curr; + else + sceKernelDelayThread(1); + lastTime = curr; } } @@ -361,49 +364,49 @@ void Run() // The main loop int main(int argc, char *argv[]) { - JLOG("SetupCallbacks()"); - SetupCallbacks(); + JLOG("SetupCallbacks()"); + SetupCallbacks(); #ifdef DEVHOOK - JLOG("initExceptionHandler()"); - initExceptionHandler(); + JLOG("initExceptionHandler()"); + initExceptionHandler(); #endif - g_engine = NULL; + g_engine = NULL; - JGameLauncher* launcher = new JGameLauncher(); + JGameLauncher* launcher = new JGameLauncher(); - u32 flags = launcher->GetInitFlags(); - if ((flags&JINIT_FLAG_ENABLE3D) != 0) - JRenderer::Set3DFlag(true); + u32 flags = launcher->GetInitFlags(); + if ((flags&JINIT_FLAG_ENABLE3D) != 0) + JRenderer::Set3DFlag(true); - JLOG("sceRtcGetTickResolution()"); - gTickFrequency = sceRtcGetTickResolution(); - JLOG("JGE::GetInstance()"); - g_engine = JGE::GetInstance(); - g_engine->SetARGV(argc, argv); + JLOG("sceRtcGetTickResolution()"); + gTickFrequency = sceRtcGetTickResolution(); + JLOG("JGE::GetInstance()"); + g_engine = JGE::GetInstance(); + g_engine->SetARGV(argc, argv); - JLOG("Create Game"); - game = launcher->GetGameApp(); - game->Create(); + JLOG("Create Game"); + game = launcher->GetGameApp(); + game->Create(); - JLOG("Run Game"); - g_engine->SetApp(game); - g_engine->Run(); + JLOG("Run Game"); + g_engine->SetApp(game); + g_engine->Run(); - game->Destroy(); - delete game; - game = NULL; + game->Destroy(); + delete game; + game = NULL; - g_engine->SetApp(NULL); + g_engine->SetApp(NULL); - done = true; + done = true; - delete launcher; + delete launcher; - JGE::Destroy(); - g_engine = NULL; + JGE::Destroy(); + g_engine = NULL; - sceKernelExitGame(); + sceKernelExitGame(); - return 0; + return 0; } diff --git a/JGE/src/pc/JGfx.cpp b/JGE/src/pc/JGfx.cpp index c5d116aaf..b63fcdeb8 100644 --- a/JGE/src/pc/JGfx.cpp +++ b/JGE/src/pc/JGfx.cpp @@ -11,8 +11,8 @@ #if (!defined IOS) && (!defined QT_CONFIG) #ifdef WIN32 - #pragma warning(disable : 4786) - #pragma comment( lib, "giflib.lib" ) +#pragma warning(disable : 4786) +#pragma comment( lib, "giflib.lib" ) #endif #include @@ -46,13 +46,13 @@ void checkGlError() { GLenum glError = glGetError(); if(glError != 0) - printf("%s : %u : GLerror is %u\n", __FUNCTION__, __LINE__, glError); + printf("%s : %u : GLerror is %u\n", __FUNCTION__, __LINE__, glError); } /*#define checkGlError() \ { \ - GLenum glError = glGetError(); \ - if(glError != 0) \ - printf("%s : %u : GLerror is %u\n", __FUNCTION__, __LINE__, glError); \ + GLenum glError = glGetError(); \ + if(glError != 0) \ + printf("%s : %u : GLerror is %u\n", __FUNCTION__, __LINE__, glError); \ }/*/ #else #define checkGlError() (void(0)) @@ -125,112 +125,113 @@ typedef void (APIENTRY *_glBlendColor) (GLclampf, GLclampf, GLclampf, GLclampf); struct glslFunctions { - void load(){ - GLSLGETPROC(glCreateShader); - GLSLGETPROC(glShaderSource); - GLSLGETPROC(glShaderBinary); - GLSLGETPROC(glCompileShader); - GLSLGETPROC(glDeleteShader); - GLSLGETPROC(glIsShader); - GLSLGETPROC(glCreateProgram); - GLSLGETPROC(glAttachShader); - GLSLGETPROC(glDetachShader); - GLSLGETPROC(glLinkProgram); - GLSLGETPROC(glUseProgram); - GLSLGETPROC(glDeleteProgram); - GLSLGETPROC(glIsProgram); - GLSLGETPROC(glGetShaderInfoLog); - GLSLGETPROC(glGetShaderiv); - GLSLGETPROC(glGetShaderSource); - GLSLGETPROC(glGetProgramiv); - GLSLGETPROC(glGetProgramInfoLog); - GLSLGETPROC(glGetUniformLocation); - GLSLGETPROC(glUniform4fv); - GLSLGETPROC(glUniform3fv); - GLSLGETPROC(glUniform2fv); - GLSLGETPROC(glUniform1fv); - GLSLGETPROC(glUniform1i); - GLSLGETPROC(glUniform1iv); - GLSLGETPROC(glUniformMatrix2fv); - GLSLGETPROC(glUniformMatrix3fv); - GLSLGETPROC(glUniformMatrix4fv); - GLSLGETPROC(glUniformMatrix2x3fv); - GLSLGETPROC(glUniformMatrix2x4fv); - GLSLGETPROC(glUniformMatrix3x2fv); - GLSLGETPROC(glUniformMatrix3x4fv); - GLSLGETPROC(glUniformMatrix4x2fv); - GLSLGETPROC(glUniformMatrix4x3fv); - GLSLGETPROC(glBindAttribLocation); - GLSLGETPROC(glGetAttribLocation); - GLSLGETPROC(glVertexAttrib1fv); - GLSLGETPROC(glVertexAttrib2fv); - GLSLGETPROC(glVertexAttrib3fv); - GLSLGETPROC(glVertexAttrib4fv); - GLSLGETPROC(glVertexAttribPointer); - GLSLGETPROC(glDisableVertexAttribArray); - GLSLGETPROC(glEnableVertexAttribArray); - GLSLGETPROC(glGetProgramBinaryOES); - GLSLGETPROC(glProgramBinaryOES); - GLSLGETPROC(glMultiTexCoord4f); - GLSLGETPROC(glActiveStencilFaceEXT); - GLSLGETPROC(glStencilOpSeparate); - GLSLGETPROC(glActiveTexture); - GLSLGETPROC(glBlendColor); - }; + void load() + { + GLSLGETPROC(glCreateShader); + GLSLGETPROC(glShaderSource); + GLSLGETPROC(glShaderBinary); + GLSLGETPROC(glCompileShader); + GLSLGETPROC(glDeleteShader); + GLSLGETPROC(glIsShader); + GLSLGETPROC(glCreateProgram); + GLSLGETPROC(glAttachShader); + GLSLGETPROC(glDetachShader); + GLSLGETPROC(glLinkProgram); + GLSLGETPROC(glUseProgram); + GLSLGETPROC(glDeleteProgram); + GLSLGETPROC(glIsProgram); + GLSLGETPROC(glGetShaderInfoLog); + GLSLGETPROC(glGetShaderiv); + GLSLGETPROC(glGetShaderSource); + GLSLGETPROC(glGetProgramiv); + GLSLGETPROC(glGetProgramInfoLog); + GLSLGETPROC(glGetUniformLocation); + GLSLGETPROC(glUniform4fv); + GLSLGETPROC(glUniform3fv); + GLSLGETPROC(glUniform2fv); + GLSLGETPROC(glUniform1fv); + GLSLGETPROC(glUniform1i); + GLSLGETPROC(glUniform1iv); + GLSLGETPROC(glUniformMatrix2fv); + GLSLGETPROC(glUniformMatrix3fv); + GLSLGETPROC(glUniformMatrix4fv); + GLSLGETPROC(glUniformMatrix2x3fv); + GLSLGETPROC(glUniformMatrix2x4fv); + GLSLGETPROC(glUniformMatrix3x2fv); + GLSLGETPROC(glUniformMatrix3x4fv); + GLSLGETPROC(glUniformMatrix4x2fv); + GLSLGETPROC(glUniformMatrix4x3fv); + GLSLGETPROC(glBindAttribLocation); + GLSLGETPROC(glGetAttribLocation); + GLSLGETPROC(glVertexAttrib1fv); + GLSLGETPROC(glVertexAttrib2fv); + GLSLGETPROC(glVertexAttrib3fv); + GLSLGETPROC(glVertexAttrib4fv); + GLSLGETPROC(glVertexAttribPointer); + GLSLGETPROC(glDisableVertexAttribArray); + GLSLGETPROC(glEnableVertexAttribArray); + GLSLGETPROC(glGetProgramBinaryOES); + GLSLGETPROC(glProgramBinaryOES); + GLSLGETPROC(glMultiTexCoord4f); + GLSLGETPROC(glActiveStencilFaceEXT); + GLSLGETPROC(glStencilOpSeparate); + GLSLGETPROC(glActiveTexture); + GLSLGETPROC(glBlendColor); + }; - _glCreateShader aglCreateShader; - _glShaderSource aglShaderSource; - _glShaderBinary aglShaderBinary; - _glCompileShader aglCompileShader; - _glDeleteShader aglDeleteShader; - _glIsShader aglIsShader; - _glCreateProgram aglCreateProgram; - _glAttachShader aglAttachShader; - _glDetachShader aglDetachShader; - _glLinkProgram aglLinkProgram; - _glUseProgram aglUseProgram; - _glDeleteProgram aglDeleteProgram; - _glIsProgram aglIsProgram; - _glGetShaderInfoLog aglGetShaderInfoLog; - _glGetShaderiv aglGetShaderiv; - _glGetShaderSource aglGetShaderSource; - _glGetProgramiv aglGetProgramiv; - _glGetProgramInfoLog aglGetProgramInfoLog; + _glCreateShader aglCreateShader; + _glShaderSource aglShaderSource; + _glShaderBinary aglShaderBinary; + _glCompileShader aglCompileShader; + _glDeleteShader aglDeleteShader; + _glIsShader aglIsShader; + _glCreateProgram aglCreateProgram; + _glAttachShader aglAttachShader; + _glDetachShader aglDetachShader; + _glLinkProgram aglLinkProgram; + _glUseProgram aglUseProgram; + _glDeleteProgram aglDeleteProgram; + _glIsProgram aglIsProgram; + _glGetShaderInfoLog aglGetShaderInfoLog; + _glGetShaderiv aglGetShaderiv; + _glGetShaderSource aglGetShaderSource; + _glGetProgramiv aglGetProgramiv; + _glGetProgramInfoLog aglGetProgramInfoLog; - _glGetUniformLocation aglGetUniformLocation; - _glUniform4fv aglUniform4fv; - _glUniform3fv aglUniform3fv; - _glUniform2fv aglUniform2fv; - _glUniform1fv aglUniform1fv; - _glUniform1i aglUniform1i; - _glUniform1iv aglUniform1iv; - _glUniformMatrix2fv aglUniformMatrix2fv; - _glUniformMatrix3fv aglUniformMatrix3fv; - _glUniformMatrix4fv aglUniformMatrix4fv; - _glUniformMatrix2x3fv aglUniformMatrix2x3fv; - _glUniformMatrix2x4fv aglUniformMatrix2x4fv; - _glUniformMatrix3x2fv aglUniformMatrix3x2fv; - _glUniformMatrix3x4fv aglUniformMatrix3x4fv; - _glUniformMatrix4x2fv aglUniformMatrix4x2fv; - _glUniformMatrix4x3fv aglUniformMatrix4x3fv; + _glGetUniformLocation aglGetUniformLocation; + _glUniform4fv aglUniform4fv; + _glUniform3fv aglUniform3fv; + _glUniform2fv aglUniform2fv; + _glUniform1fv aglUniform1fv; + _glUniform1i aglUniform1i; + _glUniform1iv aglUniform1iv; + _glUniformMatrix2fv aglUniformMatrix2fv; + _glUniformMatrix3fv aglUniformMatrix3fv; + _glUniformMatrix4fv aglUniformMatrix4fv; + _glUniformMatrix2x3fv aglUniformMatrix2x3fv; + _glUniformMatrix2x4fv aglUniformMatrix2x4fv; + _glUniformMatrix3x2fv aglUniformMatrix3x2fv; + _glUniformMatrix3x4fv aglUniformMatrix3x4fv; + _glUniformMatrix4x2fv aglUniformMatrix4x2fv; + _glUniformMatrix4x3fv aglUniformMatrix4x3fv; - _glBindAttribLocation aglBindAttribLocation; - _glGetAttribLocation aglGetAttribLocation; - _glVertexAttrib1fv aglVertexAttrib1fv; - _glVertexAttrib2fv aglVertexAttrib2fv; - _glVertexAttrib3fv aglVertexAttrib3fv; - _glVertexAttrib4fv aglVertexAttrib4fv; - _glVertexAttribPointer aglVertexAttribPointer; - _glDisableVertexAttribArray aglDisableVertexAttribArray; - _glEnableVertexAttribArray aglEnableVertexAttribArray; + _glBindAttribLocation aglBindAttribLocation; + _glGetAttribLocation aglGetAttribLocation; + _glVertexAttrib1fv aglVertexAttrib1fv; + _glVertexAttrib2fv aglVertexAttrib2fv; + _glVertexAttrib3fv aglVertexAttrib3fv; + _glVertexAttrib4fv aglVertexAttrib4fv; + _glVertexAttribPointer aglVertexAttribPointer; + _glDisableVertexAttribArray aglDisableVertexAttribArray; + _glEnableVertexAttribArray aglEnableVertexAttribArray; - _glGetProgramBinaryOES aglGetProgramBinaryOES; - _glProgramBinaryOES aglProgramBinaryOES; - _glMultiTexCoord4f aglMultiTexCoord4f; - _glActiveStencilFaceEXT aglActiveStencilFaceEXT; - _glStencilOpSeparate aglStencilOpSeparate; - _glActiveTexture aglActiveTexture; - _glBlendColor aglBlendColor; + _glGetProgramBinaryOES aglGetProgramBinaryOES; + _glProgramBinaryOES aglProgramBinaryOES; + _glMultiTexCoord4f aglMultiTexCoord4f; + _glActiveStencilFaceEXT aglActiveStencilFaceEXT; + _glStencilOpSeparate aglStencilOpSeparate; + _glActiveTexture aglActiveTexture; + _glBlendColor aglBlendColor; }; static glslFunctions g_glslfuncts; @@ -291,55 +292,55 @@ static glslFunctions g_glslfuncts; #endif JQuad::JQuad(JTexture *tex, float x, float y, float width, float height) - :mTex(tex), mX(x), mY(y), mWidth(width), mHeight(height) + :mTex(tex), mX(x), mY(y), mWidth(width), mHeight(height) { - JASSERT(tex != NULL); + JASSERT(tex != NULL); JRenderer::GetInstance()->TransferTextureToGLContext(*tex); - mHotSpotX = 0.0f; - mHotSpotY = 0.0f; - //mBlend = BLEND_DEFAULT; - for (int i=0;i<4;i++) - mColor[i].color = 0xFFFFFFFF; + mHotSpotX = 0.0f; + mHotSpotY = 0.0f; + //mBlend = BLEND_DEFAULT; + for (int i=0;i<4;i++) + mColor[i].color = 0xFFFFFFFF; - mHFlipped = false; - mVFlipped = false; + mHFlipped = false; + mVFlipped = false; - SetTextureRect(x, y, width, height); + SetTextureRect(x, y, width, height); } void JQuad::SetTextureRect(float x, float y, float w, float h) { - mX = x; - mY = y; - mWidth = w; - mHeight = h; + mX = x; + mY = y; + mWidth = w; + mHeight = h; - mTX0 = x/mTex->mTexWidth; - mTY0 = y/mTex->mTexHeight; - mTX1 = (x+w)/mTex->mTexWidth; - mTY1 = (y+h)/mTex->mTexHeight; + mTX0 = x/mTex->mTexWidth; + mTY0 = y/mTex->mTexHeight; + mTX1 = (x+w)/mTex->mTexWidth; + mTY1 = (y+h)/mTex->mTexHeight; } void JQuad::GetTextureRect(float *x, float *y, float *w, float *h) { - *x=mX; *y=mY; *w=mWidth; *h=mHeight; + *x=mX; *y=mY; *w=mWidth; *h=mHeight; } void JQuad::SetColor(PIXEL_TYPE color) { - for (int i=0;i<4;i++) - mColor[i].color = color; + for (int i=0;i<4;i++) + mColor[i].color = color; } void JQuad::SetHotSpot(float x, float y) { - mHotSpotX = x; - mHotSpotY = y; + mHotSpotX = x; + mHotSpotY = y; } @@ -347,7 +348,7 @@ void JQuad::SetHotSpot(float x, float y) JTexture::JTexture() : mBuffer(NULL) { - mTexId = -1; + mTexId = -1; } JTexture::~JTexture() @@ -367,10 +368,10 @@ JTexture::~JTexture() void JTexture::UpdateBits(int x, int y, int width, int height, PIXEL_TYPE* bits) { - checkGlError(); - JRenderer::GetInstance()->BindTexture(this); - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, bits); - checkGlError(); + checkGlError(); + JRenderer::GetInstance()->BindTexture(this); + glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, bits); + checkGlError(); } ////////////////////////////////////////////////////////////////////////// @@ -382,27 +383,27 @@ void JRenderer::Set3DFlag(bool flag) { m3DEnabled = flag; } JRenderer* JRenderer::GetInstance() { - if (mInstance == NULL) - { - mInstance = new JRenderer(); + if (mInstance == NULL) + { + mInstance = new JRenderer(); - JASSERT(mInstance != NULL); + JASSERT(mInstance != NULL); - mInstance->InitRenderer(); - } + mInstance->InitRenderer(); + } - return mInstance; + return mInstance; } void JRenderer::Destroy() { - if (mInstance) - { - mInstance->DestroyRenderer(); - delete mInstance; - mInstance = NULL; - } + if (mInstance) + { + mInstance->DestroyRenderer(); + delete mInstance; + mInstance = NULL; + } } JRenderer::JRenderer() : mActualWidth(SCREEN_WIDTH_F), mActualHeight(SCREEN_HEIGHT_F) @@ -456,111 +457,111 @@ void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB) ESMatrix tmp; int i; - for (i=0; i<4; i++) - { - tmp.m[i][0] = (srcA->m[i][0] * srcB->m[0][0]) + - (srcA->m[i][1] * srcB->m[1][0]) + - (srcA->m[i][2] * srcB->m[2][0]) + - (srcA->m[i][3] * srcB->m[3][0]) ; + for (i=0; i<4; i++) + { + tmp.m[i][0] = (srcA->m[i][0] * srcB->m[0][0]) + + (srcA->m[i][1] * srcB->m[1][0]) + + (srcA->m[i][2] * srcB->m[2][0]) + + (srcA->m[i][3] * srcB->m[3][0]) ; - tmp.m[i][1] = (srcA->m[i][0] * srcB->m[0][1]) + - (srcA->m[i][1] * srcB->m[1][1]) + - (srcA->m[i][2] * srcB->m[2][1]) + - (srcA->m[i][3] * srcB->m[3][1]) ; + tmp.m[i][1] = (srcA->m[i][0] * srcB->m[0][1]) + + (srcA->m[i][1] * srcB->m[1][1]) + + (srcA->m[i][2] * srcB->m[2][1]) + + (srcA->m[i][3] * srcB->m[3][1]) ; - tmp.m[i][2] = (srcA->m[i][0] * srcB->m[0][2]) + - (srcA->m[i][1] * srcB->m[1][2]) + - (srcA->m[i][2] * srcB->m[2][2]) + - (srcA->m[i][3] * srcB->m[3][2]) ; + tmp.m[i][2] = (srcA->m[i][0] * srcB->m[0][2]) + + (srcA->m[i][1] * srcB->m[1][2]) + + (srcA->m[i][2] * srcB->m[2][2]) + + (srcA->m[i][3] * srcB->m[3][2]) ; - tmp.m[i][3] = (srcA->m[i][0] * srcB->m[0][3]) + - (srcA->m[i][1] * srcB->m[1][3]) + - (srcA->m[i][2] * srcB->m[2][3]) + - (srcA->m[i][3] * srcB->m[3][3]) ; - } -/* - * Actually, srcA and srcB are column-major order matrixes, while they - * use row-major multiplication. Then above result equals to (B * A) likes these: + tmp.m[i][3] = (srcA->m[i][0] * srcB->m[0][3]) + + (srcA->m[i][1] * srcB->m[1][3]) + + (srcA->m[i][2] * srcB->m[2][3]) + + (srcA->m[i][3] * srcB->m[3][3]) ; + } + /* + * Actually, srcA and srcB are column-major order matrixes, while they + * use row-major multiplication. Then above result equals to (B * A) likes these: - for (i=0; i<4; i++){ + for (i=0; i<4; i++){ tmp.m[0][i] = (srcB->m[0][i] * srcA->m[0][0]) + - (srcB->m[1][i] * srcA->m[0][1]) + - (srcB->m[2][i] * srcA->m[0][2]) + - (srcB->m[3][i] * srcA->m[0][3]) ; - - tmp.m[1][i] = (srcB->m[0][i] * srcA->m[1][0]) + - (srcB->m[1][i] * srcA->m[1][1]) + - (srcB->m[2][i] * srcA->m[1][2]) + - (srcB->m[3][i] * srcA->m[1][3]) ; - - tmp.m[2][i] = (srcB->m[0][i] * srcA->m[2][0]) + - (srcB->m[1][i] * srcA->m[2][1]) + - (srcB->m[2][i] * srcA->m[2][2]) + - (srcB->m[3][i] * srcA->m[2][3]) ; - - tmp.m[3][i] = (srcB->m[0][i] * srcA->m[3][0]) + - (srcB->m[1][i] * srcA->m[3][1]) + - (srcB->m[2][i] * srcA->m[3][2]) + - (srcB->m[3][i] * srcA->m[3][3]) ; - } + (srcB->m[1][i] * srcA->m[0][1]) + + (srcB->m[2][i] * srcA->m[0][2]) + + (srcB->m[3][i] * srcA->m[0][3]) ; - * So, it works. (Refer to math method of Homogeneous Coordinate) - */ + tmp.m[1][i] = (srcB->m[0][i] * srcA->m[1][0]) + + (srcB->m[1][i] * srcA->m[1][1]) + + (srcB->m[2][i] * srcA->m[1][2]) + + (srcB->m[3][i] * srcA->m[1][3]) ; + + tmp.m[2][i] = (srcB->m[0][i] * srcA->m[2][0]) + + (srcB->m[1][i] * srcA->m[2][1]) + + (srcB->m[2][i] * srcA->m[2][2]) + + (srcB->m[3][i] * srcA->m[2][3]) ; + + tmp.m[3][i] = (srcB->m[0][i] * srcA->m[3][0]) + + (srcB->m[1][i] * srcA->m[3][1]) + + (srcB->m[2][i] * srcA->m[3][2]) + + (srcB->m[3][i] * srcA->m[3][3]) ; + } + + * So, it works. (Refer to math method of Homogeneous Coordinate) + */ memcpy(result, &tmp, sizeof(ESMatrix)); } void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { - GLfloat sinAngle, cosAngle; - GLfloat mag = sqrtf(x * x + y * y + z * z); + GLfloat sinAngle, cosAngle; + GLfloat mag = sqrtf(x * x + y * y + z * z); - sinAngle = sinf ( angle * M_PI / 180.0f ); - cosAngle = cosf ( angle * M_PI / 180.0f ); - if ( mag > 0.0f ) - { - GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs; - GLfloat oneMinusCos; - ESMatrix rotMat; + sinAngle = sinf ( angle * M_PI / 180.0f ); + cosAngle = cosf ( angle * M_PI / 180.0f ); + if ( mag > 0.0f ) + { + GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs; + GLfloat oneMinusCos; + ESMatrix rotMat; - x /= mag; - y /= mag; - z /= mag; + x /= mag; + y /= mag; + z /= mag; - xx = x * x; - yy = y * y; - zz = z * z; - xy = x * y; - yz = y * z; - zx = z * x; - xs = x * sinAngle; - ys = y * sinAngle; - zs = z * sinAngle; - oneMinusCos = 1.0f - cosAngle; + xx = x * x; + yy = y * y; + zz = z * z; + xy = x * y; + yz = y * z; + zx = z * x; + xs = x * sinAngle; + ys = y * sinAngle; + zs = z * sinAngle; + oneMinusCos = 1.0f - cosAngle; - // Note: matrixes in OpenGL ES are stored in column-major order! + // Note: matrixes in OpenGL ES are stored in column-major order! - rotMat.m[0][0] = (oneMinusCos * xx) + cosAngle; - rotMat.m[1][0] = (oneMinusCos * xy) - zs; - rotMat.m[2][0] = (oneMinusCos * zx) + ys; - rotMat.m[3][0] = 0.0F; + rotMat.m[0][0] = (oneMinusCos * xx) + cosAngle; + rotMat.m[1][0] = (oneMinusCos * xy) - zs; + rotMat.m[2][0] = (oneMinusCos * zx) + ys; + rotMat.m[3][0] = 0.0F; - rotMat.m[0][1] = (oneMinusCos * xy) + zs; - rotMat.m[1][1] = (oneMinusCos * yy) + cosAngle; - rotMat.m[2][1] = (oneMinusCos * yz) - xs; - rotMat.m[3][1] = 0.0F; + rotMat.m[0][1] = (oneMinusCos * xy) + zs; + rotMat.m[1][1] = (oneMinusCos * yy) + cosAngle; + rotMat.m[2][1] = (oneMinusCos * yz) - xs; + rotMat.m[3][1] = 0.0F; - rotMat.m[0][2] = (oneMinusCos * zx) - ys; - rotMat.m[1][2] = (oneMinusCos * yz) + xs; - rotMat.m[2][2] = (oneMinusCos * zz) + cosAngle; - rotMat.m[3][2] = 0.0F; + rotMat.m[0][2] = (oneMinusCos * zx) - ys; + rotMat.m[1][2] = (oneMinusCos * yz) + xs; + rotMat.m[2][2] = (oneMinusCos * zz) + cosAngle; + rotMat.m[3][2] = 0.0F; - rotMat.m[0][3] = 0.0F; - rotMat.m[1][3] = 0.0F; - rotMat.m[2][3] = 0.0F; - rotMat.m[3][3] = 1.0F; + rotMat.m[0][3] = 0.0F; + rotMat.m[1][3] = 0.0F; + rotMat.m[2][3] = 0.0F; + rotMat.m[3][3] = 1.0F; - esMatrixMultiply( result, &rotMat, result ); - } + esMatrixMultiply( result, &rotMat, result ); + } } void esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ) @@ -591,47 +592,47 @@ void esOrtho(ESMatrix *result, float left, float right, float bottom, float top, // GLuint esLoadShader ( GLenum type, const char *shaderSrc ) { - checkGlError(); - GLuint shader; - GLint compiled; + checkGlError(); + GLuint shader; + GLint compiled; - // Create the shader object - shader = glCreateShader ( type ); + // Create the shader object + shader = glCreateShader ( type ); - if ( shader == 0 ) + if ( shader == 0 ) return 0; - // Load the shader source - glShaderSource ( shader, 1, &shaderSrc, NULL ); + // Load the shader source + glShaderSource ( shader, 1, &shaderSrc, NULL ); - // Compile the shader - glCompileShader ( shader ); + // Compile the shader + glCompileShader ( shader ); - // Check the compile status - glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled ); + // Check the compile status + glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled ); - if ( !compiled ) - { - GLint infoLen = 0; + if ( !compiled ) + { + GLint infoLen = 0; - glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen ); + glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen ); - if ( infoLen > 1 ) - { - char* infoLog = (char*)malloc (sizeof(char) * infoLen ); + if ( infoLen > 1 ) + { + char* infoLog = (char*)malloc (sizeof(char) * infoLen ); - glGetShaderInfoLog ( shader, infoLen, NULL, infoLog ); - printf ( "Error compiling shader:\n%s\n", infoLog ); + glGetShaderInfoLog ( shader, infoLen, NULL, infoLog ); + printf ( "Error compiling shader:\n%s\n", infoLog ); - free ( infoLog ); - } + free ( infoLog ); + } - glDeleteShader ( shader ); - return 0; - } + glDeleteShader ( shader ); + return 0; + } - checkGlError(); - return shader; + checkGlError(); + return shader; } @@ -644,171 +645,171 @@ GLuint esLoadShader ( GLenum type, const char *shaderSrc ) // GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc ) { - checkGlError(); + checkGlError(); - GLuint vertexShader; - GLuint fragmentShader; - GLuint programObject; - GLint linked; + GLuint vertexShader; + GLuint fragmentShader; + GLuint programObject; + GLint linked; - // Load the vertex/fragment shaders - vertexShader = esLoadShader ( GL_VERTEX_SHADER, vertShaderSrc ); - if ( vertexShader == 0 ) - return 0; + // Load the vertex/fragment shaders + vertexShader = esLoadShader ( GL_VERTEX_SHADER, vertShaderSrc ); + if ( vertexShader == 0 ) + return 0; - fragmentShader = esLoadShader ( GL_FRAGMENT_SHADER, fragShaderSrc ); - if ( fragmentShader == 0 ) - { - glDeleteShader( vertexShader ); - return 0; - } + fragmentShader = esLoadShader ( GL_FRAGMENT_SHADER, fragShaderSrc ); + if ( fragmentShader == 0 ) + { + glDeleteShader( vertexShader ); + return 0; + } - // Create the program object - programObject = glCreateProgram ( ); + // Create the program object + programObject = glCreateProgram ( ); - if ( programObject == 0 ) - return 0; + if ( programObject == 0 ) + return 0; - glAttachShader ( programObject, vertexShader ); - glAttachShader ( programObject, fragmentShader ); + glAttachShader ( programObject, vertexShader ); + glAttachShader ( programObject, fragmentShader ); - // Link the program - glLinkProgram ( programObject ); + // Link the program + glLinkProgram ( programObject ); - // Check the link status - glGetProgramiv ( programObject, GL_LINK_STATUS, &linked ); + // Check the link status + glGetProgramiv ( programObject, GL_LINK_STATUS, &linked ); - if ( !linked ) - { - GLint infoLen = 0; + if ( !linked ) + { + GLint infoLen = 0; - glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen ); + glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen ); - if ( infoLen > 1 ) - { - char* infoLog = (char*)malloc (sizeof(char) * infoLen ); + if ( infoLen > 1 ) + { + char* infoLog = (char*)malloc (sizeof(char) * infoLen ); - glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog ); - printf( "Error linking program:\n%s\n", infoLog ); + glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog ); + printf( "Error linking program:\n%s\n", infoLog ); - free ( infoLog ); - } + free ( infoLog ); + } - glDeleteProgram ( programObject ); - return 0; - } + glDeleteProgram ( programObject ); + return 0; + } - // Free up no longer needed shader resources - glDeleteShader ( vertexShader ); - glDeleteShader ( fragmentShader ); + // Free up no longer needed shader resources + glDeleteShader ( vertexShader ); + glDeleteShader ( fragmentShader ); - checkGlError(); + checkGlError(); - return programObject; + return programObject; } #endif /* GL_ES_VERSION_2_0 || GL_VERSION_2_0*/ void JRenderer::InitRenderer() { - checkGlError(); - mCurrentTextureFilter = TEX_FILTER_NONE; - mImageFilter = NULL; + checkGlError(); + mCurrentTextureFilter = TEX_FILTER_NONE; + mImageFilter = NULL; - mCurrTexBlendSrc = BLEND_SRC_ALPHA; - mCurrTexBlendDest = BLEND_ONE_MINUS_SRC_ALPHA; + mCurrTexBlendSrc = BLEND_SRC_ALPHA; + mCurrTexBlendDest = BLEND_ONE_MINUS_SRC_ALPHA; -// mLineWidth = 1.0f; - mCurrentTex = -1; - mFOV = 75.0f; + // mLineWidth = 1.0f; + mCurrentTex = -1; + mFOV = 75.0f; #ifdef USING_MATH_TABLE - for (int i=0;i<360;i++) - { - mSinTable[i] = sinf(i*DEG2RAD); - mCosTable[i] = cosf(i*DEG2RAD); - } + for (int i=0;i<360;i++) + { + mSinTable[i] = sinf(i*DEG2RAD); + mCosTable[i] = cosf(i*DEG2RAD); + } #endif - mCurrentRenderMode = MODE_UNKNOWN; + mCurrentRenderMode = MODE_UNKNOWN; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) #ifdef FORCE_GL2 - g_glslfuncts.load(); + g_glslfuncts.load(); #endif //FORCE_GL2 - char vShader[] = - "uniform mat4 u_mvp_matrix; \n" - "attribute vec4 a_position; \n" - "attribute vec4 a_color; \n" - "varying vec4 v_color; \n" - "void main() \n" - "{ \n" - " gl_Position = u_mvp_matrix*a_position; \n" - " v_color = a_color; \n" - "} \n"; - char fShader[] = + char vShader[] = + "uniform mat4 u_mvp_matrix; \n" + "attribute vec4 a_position; \n" + "attribute vec4 a_color; \n" + "varying vec4 v_color; \n" + "void main() \n" + "{ \n" + " gl_Position = u_mvp_matrix*a_position; \n" + " v_color = a_color; \n" + "} \n"; + char fShader[] = #ifdef GL_ES_VERSION_2_0 // This line works fine on Windows, but not on Linux and it's required for GL_ES_2... hoh well - "precision mediump float; \n" + "precision mediump float; \n" #endif //GL_ES_VERSION_2_0 - "varying vec4 v_color; \n" - "void main() \n" - "{ \n" - " gl_FragColor = v_color; \n" - "} \n"; - char vShaderWithTexture[] = - "uniform mat4 u_mvp_matrix; \n" - "attribute vec4 a_position; \n" - "attribute vec2 a_texCoord; \n" - "attribute vec4 a_color; \n" - "varying vec2 v_texCoord; \n" - "varying vec4 v_color; \n" - "void main() \n" - "{ \n" - " gl_Position = u_mvp_matrix*a_position; \n" - " v_texCoord = a_texCoord; \n" - " v_color = a_color; \n" - "} \n"; - char fShaderWithTexture[] = + "varying vec4 v_color; \n" + "void main() \n" + "{ \n" + " gl_FragColor = v_color; \n" + "} \n"; + char vShaderWithTexture[] = + "uniform mat4 u_mvp_matrix; \n" + "attribute vec4 a_position; \n" + "attribute vec2 a_texCoord; \n" + "attribute vec4 a_color; \n" + "varying vec2 v_texCoord; \n" + "varying vec4 v_color; \n" + "void main() \n" + "{ \n" + " gl_Position = u_mvp_matrix*a_position; \n" + " v_texCoord = a_texCoord; \n" + " v_color = a_color; \n" + "} \n"; + char fShaderWithTexture[] = #ifdef GL_ES_VERSION_2_0 // This line works fine on Windows, but not on Linux and it's required for GL_ES_2... hoh well - "precision mediump float; \n" + "precision mediump float; \n" #endif //GL_ES_VERSION_2_0 - "varying vec2 v_texCoord; \n" - "varying vec4 v_color; \n" - "uniform sampler2D s_texture; \n" - "void main() \n" - "{ \n" - " vec4 texColor; \n" - " texColor = texture2D(s_texture, v_texCoord); \n" - " gl_FragColor = v_color*texColor; \n" - "} \n"; + "varying vec2 v_texCoord; \n" + "varying vec4 v_color; \n" + "uniform sampler2D s_texture; \n" + "void main() \n" + "{ \n" + " vec4 texColor; \n" + " texColor = texture2D(s_texture, v_texCoord); \n" + " gl_FragColor = v_color*texColor; \n" + "} \n"; - // Load the vertex/fragment shaders - prog1 = esLoadProgram(vShader, fShader); - // Get the attribute locations - prog1_positionLoc = glGetAttribLocation ( prog1, "a_position" ); - prog1_colorLoc = glGetAttribLocation ( prog1, "a_color" ); - // Get the uniform locations - prog1_mvpLoc = glGetUniformLocation( prog1, "u_mvp_matrix" ); + // Load the vertex/fragment shaders + prog1 = esLoadProgram(vShader, fShader); + // Get the attribute locations + prog1_positionLoc = glGetAttribLocation ( prog1, "a_position" ); + prog1_colorLoc = glGetAttribLocation ( prog1, "a_color" ); + // Get the uniform locations + prog1_mvpLoc = glGetUniformLocation( prog1, "u_mvp_matrix" ); - // Load the vertex/fragment shaders - prog2 = esLoadProgram(vShaderWithTexture, fShaderWithTexture); - // Get the attribute locations - prog2_positionLoc = glGetAttribLocation ( prog2, "a_position" ); - prog2_texCoordLoc = glGetAttribLocation ( prog2, "a_texCoord" ); - prog2_colorLoc = glGetAttribLocation ( prog2, "a_color" ); - // Get the uniform locations - prog2_mvpLoc = glGetUniformLocation( prog2, "u_mvp_matrix" ); - // Get the sampler location - prog2_samplerLoc = glGetUniformLocation ( prog2, "s_texture" ); + // Load the vertex/fragment shaders + prog2 = esLoadProgram(vShaderWithTexture, fShaderWithTexture); + // Get the attribute locations + prog2_positionLoc = glGetAttribLocation ( prog2, "a_position" ); + prog2_texCoordLoc = glGetAttribLocation ( prog2, "a_texCoord" ); + prog2_colorLoc = glGetAttribLocation ( prog2, "a_color" ); + // Get the uniform locations + prog2_mvpLoc = glGetUniformLocation( prog2, "u_mvp_matrix" ); + // Get the sampler location + prog2_samplerLoc = glGetUniformLocation ( prog2, "s_texture" ); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::DestroyRenderer() { - checkGlError(); + checkGlError(); #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) // Delete program object glDeleteProgram ( prog1 ); @@ -818,793 +819,801 @@ void JRenderer::DestroyRenderer() void JRenderer::BeginScene() { - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer #if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - glLoadIdentity (); // Reset The Modelview Matrix + glLoadIdentity (); // Reset The Modelview Matrix #else - esMatrixLoadIdentity(&theMvpMatrix); - esOrtho(&theMvpMatrix, 0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f,-1.0f, 1.0f); + esMatrixLoadIdentity(&theMvpMatrix); + esOrtho(&theMvpMatrix, 0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f,-1.0f, 1.0f); #endif //(!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) #ifdef WIN32 - float scaleH = mActualHeight/SCREEN_HEIGHT_F; - float scaleW = mActualWidth/SCREEN_WIDTH_F; - glScalef(scaleW,scaleH,1.f); + float scaleH = mActualHeight/SCREEN_HEIGHT_F; + float scaleW = mActualWidth/SCREEN_WIDTH_F; + if (scaleH != 1.0f || scaleW != 1.0f) + glScalef(scaleW,scaleH,1.f); #endif - checkGlError(); + checkGlError(); } void JRenderer::EndScene() { - checkGlError(); - glFlush (); - checkGlError(); + checkGlError(); + glFlush (); + checkGlError(); } void JRenderer::BindTexture(JTexture *tex) { - checkGlError(); - if (mCurrentTex != tex->mTexId) - { - mCurrentTex = tex->mTexId; + checkGlError(); + if (mCurrentTex != tex->mTexId) + { + mCurrentTex = tex->mTexId; - glBindTexture(GL_TEXTURE_2D, mCurrentTex); + glBindTexture(GL_TEXTURE_2D, mCurrentTex); - //if (mCurrentTextureFilter != tex->mFilter) - { - //mCurrentTextureFilter = tex->mFilter; - if (mCurrentTextureFilter == TEX_FILTER_LINEAR) - { - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - } - else if (mCurrentTextureFilter == TEX_FILTER_NEAREST) - { - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - } - } - } - checkGlError(); + //if (mCurrentTextureFilter != tex->mFilter) + { + //mCurrentTextureFilter = tex->mFilter; + if (mCurrentTextureFilter == TEX_FILTER_LINEAR) + { + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + } + else if (mCurrentTextureFilter == TEX_FILTER_NEAREST) + { + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + } + } + } + checkGlError(); } void JRenderer::EnableTextureFilter(bool flag) { - if (flag) - mCurrentTextureFilter = TEX_FILTER_LINEAR; - else - mCurrentTextureFilter = TEX_FILTER_NEAREST; + if (flag) + mCurrentTextureFilter = TEX_FILTER_LINEAR; + else + mCurrentTextureFilter = TEX_FILTER_NEAREST; - mCurrentTex = -1; + mCurrentTex = -1; } void Swap(float *a, float *b) { - float n=*a; - *a = *b; - *b = n; + float n=*a; + *a = *b; + *b = n; } void JRenderer::RenderQuad(JQuad* quad, float xo, float yo, float angle, float xScale, float yScale) { - checkGlError(); + checkGlError(); - //yo = SCREEN_HEIGHT-yo-1;//-(quad->mHeight); - float width = quad->mWidth; - float height = quad->mHeight; - float x = -quad->mHotSpotX; - float y = quad->mHotSpotY; + //yo = SCREEN_HEIGHT-yo-1;//-(quad->mHeight); + float width = quad->mWidth; + float height = quad->mHeight; + float x = -quad->mHotSpotX; + float y = quad->mHotSpotY; - Vector2D pt[4]; - pt[3] = Vector2D(x, y); - pt[2] = Vector2D(x+width, y); - pt[1] = Vector2D(x+width, y-height); - pt[0] = Vector2D(x, y-height); + Vector2D pt[4]; + pt[3] = Vector2D(x, y); + pt[2] = Vector2D(x+width, y); + pt[1] = Vector2D(x+width, y-height); + pt[0] = Vector2D(x, y-height); - Vector2D uv[4]; - uv[0] = Vector2D(quad->mTX0, quad->mTY1); - uv[1] = Vector2D(quad->mTX1, quad->mTY1); - uv[2] = Vector2D(quad->mTX1, quad->mTY0); - uv[3] = Vector2D(quad->mTX0, quad->mTY0); + Vector2D uv[4]; + uv[0] = Vector2D(quad->mTX0, quad->mTY1); + uv[1] = Vector2D(quad->mTX1, quad->mTY1); + uv[2] = Vector2D(quad->mTX1, quad->mTY0); + uv[3] = Vector2D(quad->mTX0, quad->mTY0); - if (quad->mHFlipped) - { - Swap(&uv[0].x, &uv[1].x); - Swap(&uv[2].x, &uv[3].x); - } + if (quad->mHFlipped) + { + Swap(&uv[0].x, &uv[1].x); + Swap(&uv[2].x, &uv[3].x); + } - if (quad->mVFlipped) - { - Swap(&uv[0].y, &uv[2].y); - Swap(&uv[1].y, &uv[3].y); - } + if (quad->mVFlipped) + { + Swap(&uv[0].y, &uv[2].y); + Swap(&uv[1].y, &uv[3].y); + } - BindTexture(quad->mTex); + BindTexture(quad->mTex); - ////glRasterPos2f(x, y); + ////glRasterPos2f(x, y); - yo = SCREEN_HEIGHT_F - yo; + yo = SCREEN_HEIGHT_F - yo; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - ESMatrix mvpMatrix; - memcpy(&mvpMatrix, &theMvpMatrix, sizeof(ESMatrix)); + ESMatrix mvpMatrix; + memcpy(&mvpMatrix, &theMvpMatrix, sizeof(ESMatrix)); - esTranslate(&mvpMatrix, xo, yo, 0.0f); + esTranslate(&mvpMatrix, xo, yo, 0.0f); - // see http://code.google.com/p/wagic/issues/detail?id=460 - esRotate(&mvpMatrix, -angle*RAD2DEG, 0.0f, 0.0f, 1.0f); - esScale(&mvpMatrix, xScale, yScale, 1.0f); + // see http://code.google.com/p/wagic/issues/detail?id=460 + esRotate(&mvpMatrix, -angle*RAD2DEG, 0.0f, 0.0f, 1.0f); + esScale(&mvpMatrix, xScale, yScale, 1.0f); - GLfloat vVertices[] = { - pt[0].x, pt[0].y, 0.0f, - uv[0].x, uv[0].y, - pt[1].x, pt[1].y, 0.0f, - uv[1].x, uv[1].y, - pt[3].x, pt[3].y, 0.0f, - uv[3].x, uv[3].y, - pt[2].x, pt[2].y, 0.0f, - uv[2].x, uv[2].y, - }; + GLfloat vVertices[] = { + pt[0].x, pt[0].y, 0.0f, + uv[0].x, uv[0].y, + pt[1].x, pt[1].y, 0.0f, + uv[1].x, uv[1].y, + pt[3].x, pt[3].y, 0.0f, + uv[3].x, uv[3].y, + pt[2].x, pt[2].y, 0.0f, + uv[2].x, uv[2].y, + }; - GLubyte colorCoords[] = { - quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, - quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, - quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, - quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, - }; + GLubyte colorCoords[] = { + quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, + quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, + quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, + quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, + }; - // Use the program object - glUseProgram ( prog2 ); - checkGlError(); + // Use the program object + glUseProgram ( prog2 ); + checkGlError(); - // Load the vertex position - glVertexAttribPointer ( prog2_positionLoc, 3, GL_FLOAT, - GL_FALSE, 5 * sizeof(GLfloat), vVertices ); - checkGlError(); - // Load the texture coordinate - glVertexAttribPointer ( prog2_texCoordLoc, 2, GL_FLOAT, - GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] ); - checkGlError(); - // Load the colors - glVertexAttribPointer ( prog2_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colorCoords ); - checkGlError(); + // Load the vertex position + glVertexAttribPointer ( prog2_positionLoc, 3, GL_FLOAT, + GL_FALSE, 5 * sizeof(GLfloat), vVertices ); + checkGlError(); + // Load the texture coordinate + glVertexAttribPointer ( prog2_texCoordLoc, 2, GL_FLOAT, + GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] ); + checkGlError(); + // Load the colors + glVertexAttribPointer ( prog2_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colorCoords ); + checkGlError(); - glEnableVertexAttribArray ( prog2_positionLoc ); - checkGlError(); - glEnableVertexAttribArray ( prog2_texCoordLoc ); - checkGlError(); - glEnableVertexAttribArray ( prog2_colorLoc ); - checkGlError(); + glEnableVertexAttribArray ( prog2_positionLoc ); + checkGlError(); + glEnableVertexAttribArray ( prog2_texCoordLoc ); + checkGlError(); + glEnableVertexAttribArray ( prog2_colorLoc ); + checkGlError(); - // Load the MVP matrix - glUniformMatrix4fv( prog2_mvpLoc, 1, GL_FALSE, (GLfloat*) &mvpMatrix.m[0][0] ); - checkGlError(); + // Load the MVP matrix + glUniformMatrix4fv( prog2_mvpLoc, 1, GL_FALSE, (GLfloat*) &mvpMatrix.m[0][0] ); + checkGlError(); - // Bind the texture - glActiveTexture ( GL_TEXTURE0 ); - checkGlError(); - glBindTexture ( GL_TEXTURE_2D, mCurrentTex ); - checkGlError(); + // Bind the texture + glActiveTexture ( GL_TEXTURE0 ); + checkGlError(); + glBindTexture ( GL_TEXTURE_2D, mCurrentTex ); + checkGlError(); - // Set the sampler texture unit to 0 - glUniform1i ( prog2_samplerLoc, 0 ); - checkGlError(); + // Set the sampler texture unit to 0 + glUniform1i ( prog2_samplerLoc, 0 ); + checkGlError(); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); - checkGlError(); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); + checkGlError(); #else - glPushMatrix(); - glTranslatef(xo, yo, 0.0f); + glPushMatrix(); + glTranslatef(xo, yo, 0.0f); + if (angle != 0) + { glRotatef(-angle*RAD2DEG, 0.0f, 0.0f, 1.0f); + } + + if (xScale != 1.0f || yScale != 1.0f) + { glScalef(xScale, yScale, 1.0f); + } #if (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat vertCoords[] = { - pt[0].x, pt[0].y, - pt[1].x, pt[1].y, - pt[3].x, pt[3].y, - pt[2].x, pt[2].y, - }; + GLfloat vertCoords[] = { + pt[0].x, pt[0].y, + pt[1].x, pt[1].y, + pt[3].x, pt[3].y, + pt[2].x, pt[2].y, + }; - GLfloat texCoords[] = { - uv[0].x, uv[0].y, - uv[1].x, uv[1].y, - uv[3].x, uv[3].y, - uv[2].x, uv[2].y, - }; + GLfloat texCoords[] = { + uv[0].x, uv[0].y, + uv[1].x, uv[1].y, + uv[3].x, uv[3].y, + uv[2].x, uv[2].y, + }; - GLubyte colorCoords[] = { - quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, - quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, - quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, - quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, - }; + GLubyte colorCoords[] = { + quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, + quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, + quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, + quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, + }; - glVertexPointer(2,GL_FLOAT,0,vertCoords); - glTexCoordPointer(2,GL_FLOAT,0, texCoords); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); + glVertexPointer(2,GL_FLOAT,0,vertCoords); + glTexCoordPointer(2,GL_FLOAT,0, texCoords); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); #else - glBegin(GL_QUADS); + glBegin(GL_QUADS); - glColor4ub(quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a); - glTexCoord2f(uv[0].x, uv[0].y); glVertex2f(pt[0].x, pt[0].y); + glColor4ub(quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a); + glTexCoord2f(uv[0].x, uv[0].y); glVertex2f(pt[0].x, pt[0].y); - // bottom right corner - glColor4ub(quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a); - glTexCoord2f(uv[1].x, uv[1].y); glVertex2f(pt[1].x, pt[1].y); + // bottom right corner + glColor4ub(quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a); + glTexCoord2f(uv[1].x, uv[1].y); glVertex2f(pt[1].x, pt[1].y); - // top right corner - glColor4ub(quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a); - glTexCoord2f(uv[2].x, uv[2].y); glVertex2f(pt[2].x, pt[2].y); + // top right corner + glColor4ub(quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a); + glTexCoord2f(uv[2].x, uv[2].y); glVertex2f(pt[2].x, pt[2].y); - // top left corner - glColor4ub(quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a); - glTexCoord2f(uv[3].x, uv[3].y); glVertex2f(pt[3].x, pt[3].y); + // top left corner + glColor4ub(quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a); + glTexCoord2f(uv[3].x, uv[3].y); glVertex2f(pt[3].x, pt[3].y); - glEnd(); + glEnd(); #endif //(defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) - glPopMatrix(); + glPopMatrix(); - //glDisable(GL_BLEND); - - // default color - glColor4ub(255, 255, 255, 255); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::RenderQuad(JQuad* quad, VertexColor* pt) { - checkGlError(); + checkGlError(); - for (int i=0;i<4;i++) - { - pt[i].y = SCREEN_HEIGHT_F - pt[i].y; - quad->mColor[i].color = pt[i].color; - } + for (int i=0;i<4;i++) + { + pt[i].y = SCREEN_HEIGHT_F - pt[i].y; + quad->mColor[i].color = pt[i].color; + } - Vector2D uv[4]; - uv[0] = Vector2D(quad->mTX0, quad->mTY1); - uv[1] = Vector2D(quad->mTX1, quad->mTY1); - uv[2] = Vector2D(quad->mTX1, quad->mTY0); - uv[3] = Vector2D(quad->mTX0, quad->mTY0); + Vector2D uv[4]; + uv[0] = Vector2D(quad->mTX0, quad->mTY1); + uv[1] = Vector2D(quad->mTX1, quad->mTY1); + uv[2] = Vector2D(quad->mTX1, quad->mTY0); + uv[3] = Vector2D(quad->mTX0, quad->mTY0); - BindTexture(quad->mTex); + BindTexture(quad->mTex); #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLfloat vVertices[] = { - pt[0].x, pt[0].y, 0.0f, - uv[0].x, uv[0].y, - pt[1].x, pt[1].y, 0.0f, - uv[1].x, uv[1].y, - pt[3].x, pt[3].y, 0.0f, - uv[3].x, uv[3].y, - pt[2].x, pt[2].y, 0.0f, - uv[2].x, uv[2].y, - }; + GLfloat vVertices[] = { + pt[0].x, pt[0].y, 0.0f, + uv[0].x, uv[0].y, + pt[1].x, pt[1].y, 0.0f, + uv[1].x, uv[1].y, + pt[3].x, pt[3].y, 0.0f, + uv[3].x, uv[3].y, + pt[2].x, pt[2].y, 0.0f, + uv[2].x, uv[2].y, + }; - GLubyte colorCoords[] = { - quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, - quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, - quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, - quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, - }; + GLubyte colorCoords[] = { + quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, + quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, + quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, + quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, + }; - // Use the program object - glUseProgram ( prog2 ); + // Use the program object + glUseProgram ( prog2 ); - // Load the vertex position - glVertexAttribPointer ( prog2_positionLoc, 3, GL_FLOAT, - GL_FALSE, 5 * sizeof(GLfloat), vVertices ); - // Load the texture coordinate - glVertexAttribPointer ( prog2_texCoordLoc, 2, GL_FLOAT, - GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] ); - // Load the colors - glVertexAttribPointer ( prog2_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colorCoords ); + // Load the vertex position + glVertexAttribPointer ( prog2_positionLoc, 3, GL_FLOAT, + GL_FALSE, 5 * sizeof(GLfloat), vVertices ); + // Load the texture coordinate + glVertexAttribPointer ( prog2_texCoordLoc, 2, GL_FLOAT, + GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] ); + // Load the colors + glVertexAttribPointer ( prog2_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colorCoords ); - glEnableVertexAttribArray ( prog2_positionLoc ); - glEnableVertexAttribArray ( prog2_texCoordLoc ); - glEnableVertexAttribArray ( prog2_colorLoc ); + glEnableVertexAttribArray ( prog2_positionLoc ); + glEnableVertexAttribArray ( prog2_texCoordLoc ); + glEnableVertexAttribArray ( prog2_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog2_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog2_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - // Bind the texture - glActiveTexture ( GL_TEXTURE0 ); - glBindTexture ( GL_TEXTURE_2D, mCurrentTex ); + // Bind the texture + glActiveTexture ( GL_TEXTURE0 ); + glBindTexture ( GL_TEXTURE_2D, mCurrentTex ); - // Set the sampler texture unit to 0 - glUniform1i ( prog2_samplerLoc, 0 ); + // Set the sampler texture unit to 0 + glUniform1i ( prog2_samplerLoc, 0 ); - //glDrawElements ( GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, indices ); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); + //glDrawElements ( GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, indices ); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat vertCoords[] = { - pt[0].x, pt[0].y, - pt[1].x, pt[1].y, - pt[3].x, pt[3].y, - pt[2].x, pt[2].y, - }; + GLfloat vertCoords[] = { + pt[0].x, pt[0].y, + pt[1].x, pt[1].y, + pt[3].x, pt[3].y, + pt[2].x, pt[2].y, + }; - GLfloat texCoords[] = { - uv[0].x, uv[0].y, - uv[1].x, uv[1].y, - uv[3].x, uv[3].y, - uv[2].x, uv[2].y, - }; + GLfloat texCoords[] = { + uv[0].x, uv[0].y, + uv[1].x, uv[1].y, + uv[3].x, uv[3].y, + uv[2].x, uv[2].y, + }; - GLubyte colorCoords[] = { - quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, - quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, - quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, - quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, - }; + GLubyte colorCoords[] = { + quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a, + quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a, + quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a, + quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a, + }; - glVertexPointer(2,GL_FLOAT,0,vertCoords); - glTexCoordPointer(2,GL_FLOAT,0, texCoords); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); + glVertexPointer(2,GL_FLOAT,0,vertCoords); + glTexCoordPointer(2,GL_FLOAT,0, texCoords); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); #else - glRasterPos2f(pt[0].x, pt[0].y); + glRasterPos2f(pt[0].x, pt[0].y); - //float w = quad->mWidth; - //float h = quad->mHeight; + //float w = quad->mWidth; + //float h = quad->mHeight; - glBegin(GL_QUADS); - // bottom left corner - glColor4ub(quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a); - glTexCoord2f(uv[0].x, uv[0].y); glVertex2f(pt[0].x, pt[0].y); + glBegin(GL_QUADS); + // bottom left corner + glColor4ub(quad->mColor[0].r, quad->mColor[0].g, quad->mColor[0].b, quad->mColor[0].a); + glTexCoord2f(uv[0].x, uv[0].y); glVertex2f(pt[0].x, pt[0].y); - // bottom right corner - glColor4ub(quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a); - glTexCoord2f(uv[1].x, uv[1].y); glVertex2f(pt[1].x, pt[1].y); + // bottom right corner + glColor4ub(quad->mColor[1].r, quad->mColor[1].g, quad->mColor[1].b, quad->mColor[1].a); + glTexCoord2f(uv[1].x, uv[1].y); glVertex2f(pt[1].x, pt[1].y); - // top right corner - glColor4ub(quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a); - glTexCoord2f(uv[2].x, uv[2].y); glVertex2f(pt[2].x, pt[2].y); + // top right corner + glColor4ub(quad->mColor[2].r, quad->mColor[2].g, quad->mColor[2].b, quad->mColor[2].a); + glTexCoord2f(uv[2].x, uv[2].y); glVertex2f(pt[2].x, pt[2].y); - // top left corner - glColor4ub(quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a); - glTexCoord2f(uv[3].x, uv[3].y); glVertex2f(pt[3].x, pt[3].y); - glEnd(); - // default color - glColor4ub(255, 255, 255, 255); + // top left corner + glColor4ub(quad->mColor[3].r, quad->mColor[3].g, quad->mColor[3].b, quad->mColor[3].a); + glTexCoord2f(uv[3].x, uv[3].y); glVertex2f(pt[3].x, pt[3].y); + glEnd(); + // default color + glColor4ub(255, 255, 255, 255); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - //glDisable(GL_BLEND); + //glDisable(GL_BLEND); - checkGlError(); + checkGlError(); } void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE color) { - checkGlError(); + checkGlError(); - y = SCREEN_HEIGHT_F - y - height; + y = SCREEN_HEIGHT_F - y - height; - JColor col; - col.color = color; + JColor col; + col.color = color; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLfloat vVertices[] = { - x, y+height, 0.0f, - x, y, 0.0f, - x+width, y+height, 0.0f, - x+width, y, 0.0f, - }; + GLfloat vVertices[] = { + x, y+height, 0.0f, + x, y, 0.0f, + x+width, y+height, 0.0f, + x+width, y, 0.0f, + }; - GLubyte colors[] = { - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - }; + GLubyte colors[] = { + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + }; - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colors); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colors); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat vVertices[] = { - x, y+height, - x, y, - x+width, y+height, - x+width, y, - }; + GLfloat vVertices[] = { + x, y+height, + x, y, + x+width, y+height, + x+width, y, + }; - GLubyte colors[] = { - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - }; + GLubyte colors[] = { + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + }; - glVertexPointer(2,GL_FLOAT,0,vVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); + glVertexPointer(2,GL_FLOAT,0,vVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); #else - glDisable(GL_TEXTURE_2D); - glColor4ub(col.r, col.g, col.b, col.a); + glDisable(GL_TEXTURE_2D); + glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_QUADS); - // top left corner - glVertex2f(x, y+height); + glBegin(GL_QUADS); + // top left corner + glVertex2f(x, y+height); - // bottom left corner - glVertex2f(x, y); + // bottom left corner + glVertex2f(x, y); - // bottom right corner - glVertex2f(x+width, y); + // bottom right corner + glVertex2f(x+width, y); - // top right corner - glVertex2f(x+width, y+height); + // top right corner + glVertex2f(x+width, y+height); - glEnd(); - // default color - glColor4ub(255, 255, 255, 255); - glEnable(GL_TEXTURE_2D); + glEnd(); + // default color + glColor4ub(255, 255, 255, 255); + glEnable(GL_TEXTURE_2D); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::DrawRect(float x, float y, float width, float height, PIXEL_TYPE color) { - checkGlError(); + checkGlError(); - y = SCREEN_HEIGHT_F - y - height; + y = SCREEN_HEIGHT_F - y - height; - JColor col; - col.color = color; + JColor col; + col.color = color; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLfloat vVertices[] = { - x, y, 0.0f, - x, y+height, 0.0f, - x+width, y+height, 0.0f, - x+width, y, 0.0f, - }; + GLfloat vVertices[] = { + x, y, 0.0f, + x, y+height, 0.0f, + x+width, y+height, 0.0f, + x+width, y, 0.0f, + }; - GLubyte colors[] = { - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - }; + GLubyte colors[] = { + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + }; - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colors); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colors); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_LINE_LOOP,0,4); + glDrawArrays(GL_LINE_LOOP,0,4); #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat vertCoords[] = { - x, y, - x, y+height, - x+width, y+height, - x+width, y, - }; + GLfloat vertCoords[] = { + x, y, + x, y+height, + x+width, y+height, + x+width, y, + }; - GLubyte colorCoords[] = { - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - }; + GLubyte colorCoords[] = { + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + }; - glVertexPointer(2,GL_FLOAT,0,vertCoords); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); - glDrawArrays(GL_LINE_LOOP,0,4); + glVertexPointer(2,GL_FLOAT,0,vertCoords); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); + glDrawArrays(GL_LINE_LOOP,0,4); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); #else - glDisable(GL_TEXTURE_2D); - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_LINES); + glDisable(GL_TEXTURE_2D); + glColor4ub(col.r, col.g, col.b, col.a); + glBegin(GL_LINES); - glVertex2f(x, y); - glVertex2f(x, y+height); + glVertex2f(x, y); + glVertex2f(x, y+height); - glVertex2f(x, y+height); - glVertex2f(x+width, y+height); + glVertex2f(x, y+height); + glVertex2f(x+width, y+height); - glVertex2f(x+width, y+height); - glVertex2f(x+width, y); + glVertex2f(x+width, y+height); + glVertex2f(x+width, y); - glVertex2f(x+width, y); - glVertex2f(x, y); + glVertex2f(x+width, y); + glVertex2f(x, y); - glEnd(); + glEnd(); - // default color - glColor4ub(255, 255, 255, 255); - glEnable(GL_TEXTURE_2D); + // default color + glColor4ub(255, 255, 255, 255); + glEnable(GL_TEXTURE_2D); #endif //#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE* colors) { - JColor col[4]; - for (int i=0;i<4;i++) - col[i].color = colors[i]; + JColor col[4]; + for (int i=0;i<4;i++) + col[i].color = colors[i]; - FillRect(x, y, width, height, col); + FillRect(x, y, width, height, col); } void JRenderer::FillRect(float x, float y, float width, float height, JColor* colors) { - checkGlError(); - y = SCREEN_HEIGHT_F - y - height; + checkGlError(); + y = SCREEN_HEIGHT_F - y - height; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLfloat vVertices[] = { - x, y+height, 0.0f, - x, y, 0.0f, - x+width, y+height, 0.0f, - x+width, y, 0.0f, - }; + GLfloat vVertices[] = { + x, y+height, 0.0f, + x, y, 0.0f, + x+width, y+height, 0.0f, + x+width, y, 0.0f, + }; - GLubyte cols[] = { - colors[0].r, colors[0].g, colors[0].b, colors[0].a, - colors[2].r, colors[2].g, colors[2].b, colors[2].a, - colors[1].r, colors[1].g, colors[1].b, colors[1].a, - colors[3].r, colors[3].g, colors[3].b, colors[3].a, - }; + GLubyte cols[] = { + colors[0].r, colors[0].g, colors[0].b, colors[0].a, + colors[2].r, colors[2].g, colors[2].b, colors[2].a, + colors[1].r, colors[1].g, colors[1].b, colors[1].a, + colors[3].r, colors[3].g, colors[3].b, colors[3].a, + }; - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), cols); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), cols); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat vVertices[] = { - x, y+height, - x, y, - x+width, y+height, - x+width, y, - }; + GLfloat vVertices[] = { + x, y+height, + x, y, + x+width, y+height, + x+width, y, + }; - GLubyte cols[] = { - colors[0].r, colors[0].g, colors[0].b, colors[0].a, - colors[2].r, colors[2].g, colors[2].b, colors[2].a, - colors[1].r, colors[1].g, colors[1].b, colors[1].a, - colors[3].r, colors[3].g, colors[3].b, colors[3].a, - }; + GLubyte cols[] = { + colors[0].r, colors[0].g, colors[0].b, colors[0].a, + colors[2].r, colors[2].g, colors[2].b, colors[2].a, + colors[1].r, colors[1].g, colors[1].b, colors[1].a, + colors[3].r, colors[3].g, colors[3].b, colors[3].a, + }; - glVertexPointer(2,GL_FLOAT,0,vVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, cols ); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); + glVertexPointer(2,GL_FLOAT,0,vVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, cols ); + glDrawArrays(GL_TRIANGLE_STRIP,0,4); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); #else - glDisable(GL_TEXTURE_2D); - glBegin(GL_QUADS); - // top left corner - glColor4ub(colors[0].r, colors[0].g, colors[0].b, colors[0].a); - glVertex2f(x, y+height); + glDisable(GL_TEXTURE_2D); + glBegin(GL_QUADS); + // top left corner + glColor4ub(colors[0].r, colors[0].g, colors[0].b, colors[0].a); + glVertex2f(x, y+height); - // bottom left corner - glColor4ub(colors[2].r, colors[2].g, colors[2].b, colors[2].a); - glVertex2f(x, y); + // bottom left corner + glColor4ub(colors[2].r, colors[2].g, colors[2].b, colors[2].a); + glVertex2f(x, y); - // bottom right corner - glColor4ub(colors[3].r, colors[3].g, colors[3].b, colors[3].a); - glVertex2f(x+width, y); + // bottom right corner + glColor4ub(colors[3].r, colors[3].g, colors[3].b, colors[3].a); + glVertex2f(x+width, y); - // top right corner - glColor4ub(colors[1].r, colors[1].g, colors[1].b, colors[1].a); - glVertex2f(x+width, y+height); + // top right corner + glColor4ub(colors[1].r, colors[1].g, colors[1].b, colors[1].a); + glVertex2f(x+width, y+height); - glEnd(); + glEnd(); - // default color - glColor4ub(255, 255, 255, 255); - glEnable(GL_TEXTURE_2D); + // default color + glColor4ub(255, 255, 255, 255); + glEnable(GL_TEXTURE_2D); #endif //#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - //glDisable(GL_BLEND); - checkGlError(); + //glDisable(GL_BLEND); + checkGlError(); } void JRenderer::DrawLine(float x1, float y1, float x2, float y2, PIXEL_TYPE color) { - checkGlError(); -// glLineWidth (mLineWidth); - JColor col; - col.color = color; + checkGlError(); + // glLineWidth (mLineWidth); + JColor col; + col.color = color; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLfloat vVertices[] = { - x1, SCREEN_HEIGHT_F-y1, 0.0f, - x2, SCREEN_HEIGHT_F-y2, 0.0f, - }; + GLfloat vVertices[] = { + x1, SCREEN_HEIGHT_F-y1, 0.0f, + x2, SCREEN_HEIGHT_F-y2, 0.0f, + }; - GLubyte cols[] = { - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - }; + GLubyte cols[] = { + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + }; - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), cols); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), cols); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_LINES,0,2); + glDrawArrays(GL_LINES,0,2); #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat vVertices[] = { - x1, SCREEN_HEIGHT_F-y1, 0.0f, - x2, SCREEN_HEIGHT_F-y2, 0.0f, - }; + GLfloat vVertices[] = { + x1, SCREEN_HEIGHT_F-y1, 0.0f, + x2, SCREEN_HEIGHT_F-y2, 0.0f, + }; - GLubyte cols[] = { - col.r, col.g, col.b, col.a, - col.r, col.g, col.b, col.a, - }; + GLubyte cols[] = { + col.r, col.g, col.b, col.a, + col.r, col.g, col.b, col.a, + }; - glVertexPointer(2,GL_FLOAT,0,vVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, cols ); - glDrawArrays(GL_LINES,0,2); + glVertexPointer(2,GL_FLOAT,0,vVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, cols ); + glDrawArrays(GL_LINES,0,2); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); #else - glDisable(GL_TEXTURE_2D); - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_LINES); - glVertex2f(x1, SCREEN_HEIGHT_F-y1); - glVertex2f(x2, SCREEN_HEIGHT_F-y2); - glEnd(); - glColor4ub(255, 255, 255, 255); - glEnable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); + + if (color != 0xFFFFFFFF) + glColor4ub(col.r, col.g, col.b, col.a); + + glBegin(GL_LINES); + glVertex2f(x1, SCREEN_HEIGHT_F-y1); + glVertex2f(x2, SCREEN_HEIGHT_F-y2); + glEnd(); + if (color != 0xFFFFFFFF) + glColor4ub(255, 255, 255, 255); + glEnable(GL_TEXTURE_2D); #endif //#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::Plot(float x, float y, PIXEL_TYPE color) { - checkGlError(); - glDisable(GL_TEXTURE_2D); - JColor col; - col.color = color; + checkGlError(); + glDisable(GL_TEXTURE_2D); + JColor col; + col.color = color; #if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) && (!defined GL_VERSION_ES_CM_1_1) - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_POINTS); - glVertex2f(x, SCREEN_HEIGHT_F-y); - glEnd(); - glColor4ub(255, 255, 255, 255); + glColor4ub(col.r, col.g, col.b, col.a); + glBegin(GL_POINTS); + glVertex2f(x, SCREEN_HEIGHT_F-y); + glEnd(); + glColor4ub(255, 255, 255, 255); #else - // FIXME, not used + // FIXME, not used #endif //#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - glEnable(GL_TEXTURE_2D); - checkGlError(); + glEnable(GL_TEXTURE_2D); + checkGlError(); } void JRenderer::PlotArray(float *x, float *y, int count, PIXEL_TYPE color) { - checkGlError(); - glDisable(GL_TEXTURE_2D); - JColor col; - col.color = color; + checkGlError(); + glDisable(GL_TEXTURE_2D); + JColor col; + col.color = color; #if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) && (!defined GL_VERSION_ES_CM_1_1) - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_POINTS); - for (int i=0;i>= 1; - b = 1 << n; - if (b == 2 * width) b >>= 1; - return b; + int b = width; + int n; + for (n = 0; b != 0; n++) b >>= 1; + b = 1 << n; + if (b == 2 * width) b >>= 1; + return b; } @@ -1634,30 +1643,30 @@ static void jpg_null(j_decompress_ptr cinfo __attribute__((unused))) static boolean jpg_fill_input_buffer(j_decompress_ptr cinfo __attribute__((unused))) { - //// ri.Con_Printf(PRINT_ALL, "Premature end of JPEG data\n"); - return 1; + //// ri.Con_Printf(PRINT_ALL, "Premature end of JPEG data\n"); + return 1; } static void jpg_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { - cinfo->src->next_input_byte += (size_t) num_bytes; - cinfo->src->bytes_in_buffer -= (size_t) num_bytes; + cinfo->src->next_input_byte += (size_t) num_bytes; + cinfo->src->bytes_in_buffer -= (size_t) num_bytes; - //// if (cinfo->src->bytes_in_buffer < 0) - //// ri.Con_Printf(PRINT_ALL, "Premature end of JPEG data\n"); + //// if (cinfo->src->bytes_in_buffer < 0) + //// ri.Con_Printf(PRINT_ALL, "Premature end of JPEG data\n"); } static void jpeg_mem_src(j_decompress_ptr cinfo, byte *mem, int len) { - cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(struct jpeg_source_mgr)); - cinfo->src->init_source = jpg_null; - cinfo->src->fill_input_buffer = jpg_fill_input_buffer; - cinfo->src->skip_input_data = jpg_skip_input_data; - cinfo->src->resync_to_restart = jpeg_resync_to_restart; - cinfo->src->term_source = jpg_null; - cinfo->src->bytes_in_buffer = len; - cinfo->src->next_input_byte = mem; + cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(struct jpeg_source_mgr)); + cinfo->src->init_source = jpg_null; + cinfo->src->fill_input_buffer = jpg_fill_input_buffer; + cinfo->src->skip_input_data = jpg_skip_input_data; + cinfo->src->resync_to_restart = jpeg_resync_to_restart; + cinfo->src->term_source = jpg_null; + cinfo->src->bytes_in_buffer = len; + cinfo->src->next_input_byte = mem; } /* @@ -1667,143 +1676,143 @@ LoadJPG */ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode __attribute__((unused)), int TextureFormat __attribute__((unused))) { - textureInfo.mBits = NULL; + textureInfo.mBits = NULL; - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - BYTE *rawdata, *rgbadata, *scanline, *p, *q; - int rawsize, i; + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + BYTE *rawdata, *rgbadata, *scanline, *p, *q; + int rawsize, i; - JFileSystem* fileSystem = JFileSystem::GetInstance(); - if (!fileSystem->OpenFile(filename)) return; + JFileSystem* fileSystem = JFileSystem::GetInstance(); + if (!fileSystem->OpenFile(filename)) return; - rawsize = fileSystem->GetFileSize(); + rawsize = fileSystem->GetFileSize(); - rawdata = new BYTE[rawsize]; + rawdata = new BYTE[rawsize]; - if (!rawdata) - { - fileSystem->CloseFile(); - return; - } - - fileSystem->ReadFile(rawdata, rawsize); + if (!rawdata) + { fileSystem->CloseFile(); + return; + } - // Initialize libJpeg Object - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); + fileSystem->ReadFile(rawdata, rawsize); + fileSystem->CloseFile(); - jpeg_mem_src(&cinfo, rawdata, rawsize); + // Initialize libJpeg Object + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); - // Process JPEG header - jpeg_read_header(&cinfo, true); + jpeg_mem_src(&cinfo, rawdata, rawsize); + + // Process JPEG header + jpeg_read_header(&cinfo, true); - // Start Decompression - jpeg_start_decompress(&cinfo); + // Start Decompression + jpeg_start_decompress(&cinfo); - // Check Colour Components - if(cinfo.output_components != 3 && cinfo.output_components != 4) - { - //// ri.Con_Printf(PRINT_ALL, "Invalid JPEG colour components\n"); - jpeg_destroy_decompress(&cinfo); - //// ri.FS_FreeFile(rawdata); - return; - } + // Check Colour Components + if(cinfo.output_components != 3 && cinfo.output_components != 4) + { + //// ri.Con_Printf(PRINT_ALL, "Invalid JPEG colour components\n"); + jpeg_destroy_decompress(&cinfo); + //// ri.FS_FreeFile(rawdata); + return; + } - int tw = getNextPower2(cinfo.output_width); - int th = getNextPower2(cinfo.output_height); + int tw = getNextPower2(cinfo.output_width); + int th = getNextPower2(cinfo.output_height); - // Allocate Memory for decompressed image - rgbadata = new BYTE[tw * th * 4]; - if(!rgbadata) - { - //// ri.Con_Printf(PRINT_ALL, "Insufficient RAM for JPEG buffer\n"); - jpeg_destroy_decompress(&cinfo); - //// ri.FS_FreeFile(rawdata); - delete [] rgbadata; - return; - } + // Allocate Memory for decompressed image + rgbadata = new BYTE[tw * th * 4]; + if(!rgbadata) + { + //// ri.Con_Printf(PRINT_ALL, "Insufficient RAM for JPEG buffer\n"); + jpeg_destroy_decompress(&cinfo); + //// ri.FS_FreeFile(rawdata); + delete [] rgbadata; + return; + } - // Pass sizes to output + // Pass sizes to output - // Allocate Scanline buffer - scanline = (byte *)malloc(cinfo.output_width * 3); - if(!scanline) - { - //// ri.Con_Printf(PRINT_ALL, "Insufficient RAM for JPEG scanline buffer\n"); + // Allocate Scanline buffer + scanline = (byte *)malloc(cinfo.output_width * 3); + if(!scanline) + { + //// ri.Con_Printf(PRINT_ALL, "Insufficient RAM for JPEG scanline buffer\n"); - jpeg_destroy_decompress(&cinfo); - //// ri.FS_FreeFile(rawdata); + jpeg_destroy_decompress(&cinfo); + //// ri.FS_FreeFile(rawdata); - delete [] rgbadata; - return; - } + delete [] rgbadata; + return; + } - // Read Scanlines, and expand from RGB to RGBA - BYTE* currRow = rgbadata; + // Read Scanlines, and expand from RGB to RGBA + BYTE* currRow = rgbadata; - while(cinfo.output_scanline < cinfo.output_height) - { - p = scanline; - jpeg_read_scanlines(&cinfo, &scanline, 1); + while(cinfo.output_scanline < cinfo.output_height) + { + p = scanline; + jpeg_read_scanlines(&cinfo, &scanline, 1); - q = currRow; - for(i=0; i<(int)cinfo.output_width; i++) - { - q[0] = p[0]; - q[1] = p[1]; - q[2] = p[2]; - q[3] = 255; + q = currRow; + for(i=0; i<(int)cinfo.output_width; i++) + { + q[0] = p[0]; + q[1] = p[1]; + q[2] = p[2]; + q[3] = 255; - p+=3; q+=4; - } - currRow += tw*4; - } + p+=3; q+=4; + } + currRow += tw*4; + } - // Free the scanline buffer - free(scanline); + // Free the scanline buffer + free(scanline); - textureInfo.mBits = rgbadata; - textureInfo.mWidth = cinfo.output_width; - textureInfo.mHeight = cinfo.output_height; - textureInfo.mTexWidth = tw; - textureInfo.mTexHeight = th; + textureInfo.mBits = rgbadata; + textureInfo.mWidth = cinfo.output_width; + textureInfo.mHeight = cinfo.output_height; + textureInfo.mTexWidth = tw; + textureInfo.mTexHeight = th; - // Finish Decompression - try { - jpeg_finish_decompress(&cinfo); - } catch(...) {} + // Finish Decompression + try { + jpeg_finish_decompress(&cinfo); + } catch(...) {} - // Destroy JPEG object - jpeg_destroy_decompress(&cinfo); + // Destroy JPEG object + jpeg_destroy_decompress(&cinfo); - delete[] rawdata; + delete[] rawdata; } static void PNGCustomWarningFn(png_structp png_ptr __attribute__((unused)), png_const_charp warning_msg __attribute__((unused))) { - // ignore PNG warnings + // ignore PNG warnings } static void PNGCustomReadDataFn(png_structp png_ptr, png_bytep data, png_size_t length) { - png_size_t check; + png_size_t check; - JFileSystem *fileSystem = (JFileSystem*)png_ptr->io_ptr; + JFileSystem *fileSystem = (JFileSystem*)png_ptr->io_ptr; - check = fileSystem->ReadFile(data, length); + check = fileSystem->ReadFile(data, length); - if (check != length) - { - png_error(png_ptr, "Read Error!"); - } + if (check != length) + { + png_error(png_ptr, "Read Error!"); + } } JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused))) @@ -1843,15 +1852,15 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm tex->mBuffer = textureInfo.mBits; } - + return tex; } int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode __attribute__((unused)), int TextureFormat __attribute__((unused))) { - textureInfo.mBits = NULL; + textureInfo.mBits = NULL; - DWORD* p32; + DWORD* p32; png_structp png_ptr; png_infop info_ptr; @@ -1860,14 +1869,14 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode int bit_depth, color_type, interlace_type, x, y; DWORD* line; - JFileSystem* fileSystem = JFileSystem::GetInstance(); - if (!fileSystem->OpenFile(filename)) - return JGE_ERR_CANT_OPEN_FILE; + JFileSystem* fileSystem = JFileSystem::GetInstance(); + if (!fileSystem->OpenFile(filename)) + return JGE_ERR_CANT_OPEN_FILE; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) - { - fileSystem->CloseFile(); + { + fileSystem->CloseFile(); return JGE_ERR_PNG; } @@ -1875,16 +1884,16 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, PNGCustomWarningFn); info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) - { + { //fclose(fp); - fileSystem->CloseFile(); + fileSystem->CloseFile(); png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL); return JGE_ERR_PNG; } png_init_io(png_ptr, NULL); - png_set_read_fn(png_ptr, (png_voidp)fileSystem, PNGCustomReadDataFn); + png_set_read_fn(png_ptr, (png_voidp)fileSystem, PNGCustomReadDataFn); png_set_sig_bytes(png_ptr, sig_read); png_read_info(png_ptr, info_ptr); @@ -1896,52 +1905,52 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); - line = (DWORD*) malloc(width * 4); + line = (DWORD*) malloc(width * 4); if (!line) - { + { //fclose(fp); - fileSystem->CloseFile(); + fileSystem->CloseFile(); png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL); return JGE_ERR_MALLOC_FAILED; } - tw = getNextPower2(width); - th = getNextPower2(height); + tw = getNextPower2(width); + th = getNextPower2(height); - int size = tw * th * 4; // RGBA + int size = tw * th * 4; // RGBA - BYTE* buffer = new BYTE[size]; + BYTE* buffer = new BYTE[size]; - //JTexture *tex = new JTexture(); + //JTexture *tex = new JTexture(); - if (buffer) - { + if (buffer) + { - p32 = (DWORD*) buffer; + p32 = (DWORD*) buffer; - for (y = 0; y < (int)height; y++) - { - png_read_row(png_ptr, (BYTE*) line, png_bytep_NULL); - for (x = 0; x < (int)width; x++) - { - DWORD color32 = line[x]; - int a = (color32 >> 24) & 0xff; - int r = color32 & 0xff; - int g = (color32 >> 8) & 0xff; - int b = (color32 >> 16) & 0xff; + for (y = 0; y < (int)height; y++) + { + png_read_row(png_ptr, (BYTE*) line, png_bytep_NULL); + for (x = 0; x < (int)width; x++) + { + DWORD color32 = line[x]; + int a = (color32 >> 24) & 0xff; + int r = color32 & 0xff; + int g = (color32 >> 8) & 0xff; + int b = (color32 >> 16) & 0xff; - color32 = r | (g << 8) | (b << 16) | (a << 24); - *(p32+x) = color32; + color32 = r | (g << 8) | (b << 16) | (a << 24); + *(p32+x) = color32; - } - p32 += tw; + } + p32 += tw; - } + } - } + } free (line); @@ -1949,17 +1958,17 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode png_read_end(png_ptr, info_ptr); png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); - fileSystem->CloseFile(); + fileSystem->CloseFile(); - textureInfo.mBits = buffer; - textureInfo.mWidth = width; - textureInfo.mHeight = height; - textureInfo.mTexWidth = tw; - textureInfo.mTexHeight = th; + textureInfo.mBits = buffer; + textureInfo.mWidth = width; + textureInfo.mHeight = height; + textureInfo.mTexWidth = tw; + textureInfo.mTexHeight = th; - return 1; - //return textureInfo; + return 1; + //return textureInfo; } @@ -1979,161 +1988,161 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode int JRenderer::image_readgif(void * handle, TextureInfo &textureInfo, DWORD * bgcolor, InputFunc readFunc, int mode __attribute__((unused)), int TextureFormat __attribute__((unused))) { - // pixel ** image_data=NULL; - DWORD *p32=NULL; - // DWORD *buff=NULL; - //#define gif_color(c) RGB(palette->Colors[c].Red, palette->Colors[c].Green, palette->Colors[c].Blue) + // pixel ** image_data=NULL; + DWORD *p32=NULL; + // DWORD *buff=NULL; + //#define gif_color(c) RGB(palette->Colors[c].Red, palette->Colors[c].Green, palette->Colors[c].Blue) #define gif_color32(c) ARGB(255,palette->Colors[c].Blue,palette->Colors[c].Green, palette->Colors[c].Red) - GifRecordType RecordType; - GifByteType *Extension; - GifRowType LineIn = NULL; - GifFileType *GifFileIn = NULL; - ColorMapObject *palette; - int ExtCode; - if ((GifFileIn = DGifOpen(handle, readFunc)) == NULL) - return 1; - *bgcolor = 0; - textureInfo.mWidth = 0; - textureInfo.mHeight = 0; - //*image_data = NULL; + GifRecordType RecordType; + GifByteType *Extension; + GifRowType LineIn = NULL; + GifFileType *GifFileIn = NULL; + ColorMapObject *palette; + int ExtCode; + if ((GifFileIn = DGifOpen(handle, readFunc)) == NULL) + return 1; + *bgcolor = 0; + textureInfo.mWidth = 0; + textureInfo.mHeight = 0; + //*image_data = NULL; - do { - if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR) - { - DGifCloseFile(GifFileIn); - return 1; - } + do { + if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR) + { + DGifCloseFile(GifFileIn); + return 1; + } - switch (RecordType) { - case IMAGE_DESC_RECORD_TYPE: - { - if (DGifGetImageDesc(GifFileIn) == GIF_ERROR) - { - DGifCloseFile(GifFileIn); - return 1; - } - if((palette = (GifFileIn->SColorMap != NULL) ? GifFileIn->SColorMap : GifFileIn->Image.ColorMap) == NULL) - { - DGifCloseFile(GifFileIn); - return 1; - } - textureInfo.mWidth = GifFileIn->Image.Width; - textureInfo.mHeight = GifFileIn->Image.Height; - *bgcolor = gif_color32(GifFileIn->SBackGroundColor); - if((LineIn = (GifRowType) malloc(GifFileIn->Image.Width * sizeof(GifPixelType))) == NULL) - { - DGifCloseFile(GifFileIn); - return 1; - } - textureInfo.mTexWidth = getNextPower2(GifFileIn->Image.Width); - textureInfo.mTexHeight = getNextPower2(GifFileIn->Image.Height); + switch (RecordType) { + case IMAGE_DESC_RECORD_TYPE: + { + if (DGifGetImageDesc(GifFileIn) == GIF_ERROR) + { + DGifCloseFile(GifFileIn); + return 1; + } + if((palette = (GifFileIn->SColorMap != NULL) ? GifFileIn->SColorMap : GifFileIn->Image.ColorMap) == NULL) + { + DGifCloseFile(GifFileIn); + return 1; + } + textureInfo.mWidth = GifFileIn->Image.Width; + textureInfo.mHeight = GifFileIn->Image.Height; + *bgcolor = gif_color32(GifFileIn->SBackGroundColor); + if((LineIn = (GifRowType) malloc(GifFileIn->Image.Width * sizeof(GifPixelType))) == NULL) + { + DGifCloseFile(GifFileIn); + return 1; + } + textureInfo.mTexWidth = getNextPower2(GifFileIn->Image.Width); + textureInfo.mTexHeight = getNextPower2(GifFileIn->Image.Height); - //if((*image_data = (pixel *)malloc(sizeof(pixel) * GifFileIn->Image.Width * GifFileIn->Image.Height)) == NULL) - if((p32 = (DWORD *)malloc(sizeof(PIXEL_TYPE) * textureInfo.mTexWidth * textureInfo.mTexHeight)) == NULL) - { - free((void *)LineIn); - DGifCloseFile(GifFileIn); - return 1; - } - DWORD * curr = p32; - DWORD * imgdata; - for (GifWord i = 0; i < GifFileIn->Image.Height; i ++) - { - imgdata = curr; - if (DGifGetLine(GifFileIn, LineIn, GifFileIn->Image.Width) == GIF_ERROR) - { - free((void *)p32); - free((void *)LineIn); - DGifCloseFile(GifFileIn); - return 1; - } - for (GifWord j = 0; j < GifFileIn->Image.Width; j ++) - { - DWORD color32 = gif_color32(LineIn[j]); + //if((*image_data = (pixel *)malloc(sizeof(pixel) * GifFileIn->Image.Width * GifFileIn->Image.Height)) == NULL) + if((p32 = (DWORD *)malloc(sizeof(PIXEL_TYPE) * textureInfo.mTexWidth * textureInfo.mTexHeight)) == NULL) + { + free((void *)LineIn); + DGifCloseFile(GifFileIn); + return 1; + } + DWORD * curr = p32; + DWORD * imgdata; + for (GifWord i = 0; i < GifFileIn->Image.Height; i ++) + { + imgdata = curr; + if (DGifGetLine(GifFileIn, LineIn, GifFileIn->Image.Width) == GIF_ERROR) + { + free((void *)p32); + free((void *)LineIn); + DGifCloseFile(GifFileIn); + return 1; + } + for (GifWord j = 0; j < GifFileIn->Image.Width; j ++) + { + DWORD color32 = gif_color32(LineIn[j]); - //if(mTexLoadingCB) mTexLoadingCB(color32); - //if(JRenderer::GetInstance()->GetTextureLoadingCallback()) - // JRenderer::GetInstance()->GetTextureLoadingCallback()(color32); + //if(mTexLoadingCB) mTexLoadingCB(color32); + //if(JRenderer::GetInstance()->GetTextureLoadingCallback()) + // JRenderer::GetInstance()->GetTextureLoadingCallback()(color32); - *imgdata++ = color32; - } + *imgdata++ = color32; + } - curr += textureInfo.mTexWidth; - } - textureInfo.mBits = (u8 *)p32; - break; - } - case EXTENSION_RECORD_TYPE: - if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR) - { - if(textureInfo.mBits != NULL) - { - free((void *)textureInfo.mBits); - textureInfo.mBits = NULL; - } - if(LineIn != NULL) - free((void *)LineIn); - DGifCloseFile(GifFileIn); - return 1; - } - while (Extension != NULL) { - if (DGifGetExtensionNext(GifFileIn, &Extension) == GIF_ERROR) - { - if(textureInfo.mBits != NULL) - { - free((void *)textureInfo.mBits); - textureInfo.mBits = NULL; - } - if(LineIn != NULL) - free((void *)LineIn); - DGifCloseFile(GifFileIn); - return 1; - } - } - break; - case TERMINATE_RECORD_TYPE: - break; - default: - break; - } - } - while (RecordType != TERMINATE_RECORD_TYPE); + curr += textureInfo.mTexWidth; + } + textureInfo.mBits = (u8 *)p32; + break; + } + case EXTENSION_RECORD_TYPE: + if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR) + { + if(textureInfo.mBits != NULL) + { + free((void *)textureInfo.mBits); + textureInfo.mBits = NULL; + } + if(LineIn != NULL) + free((void *)LineIn); + DGifCloseFile(GifFileIn); + return 1; + } + while (Extension != NULL) { + if (DGifGetExtensionNext(GifFileIn, &Extension) == GIF_ERROR) + { + if(textureInfo.mBits != NULL) + { + free((void *)textureInfo.mBits); + textureInfo.mBits = NULL; + } + if(LineIn != NULL) + free((void *)LineIn); + DGifCloseFile(GifFileIn); + return 1; + } + } + break; + case TERMINATE_RECORD_TYPE: + break; + default: + break; + } + } + while (RecordType != TERMINATE_RECORD_TYPE); - if(LineIn != NULL) - free((void *)LineIn); - DGifCloseFile(GifFileIn); + if(LineIn != NULL) + free((void *)LineIn); + DGifCloseFile(GifFileIn); - return 0; + return 0; } int image_gif_read(GifFileType * ft, GifByteType * buf, int size) { - JFileSystem *fileSys = (JFileSystem *)ft->UserData; - //return fread(buf, 1, size, (FILE *)ft->UserData); - if (fileSys->ReadFile(buf, size)) - return size; - else - return 0; + JFileSystem *fileSys = (JFileSystem *)ft->UserData; + //return fread(buf, 1, size, (FILE *)ft->UserData); + if (fileSys->ReadFile(buf, size)) + return size; + else + return 0; } void JRenderer::LoadGIF(TextureInfo &textureInfo, const char *filename, int mode, int TextureFormat __attribute__((unused))) { - ///* - //FILE * fp = fopen(filename, "rb"); - JFileSystem *fileSys = JFileSystem::GetInstance(); - if (!fileSys->OpenFile(filename)) - return; + ///* + //FILE * fp = fopen(filename, "rb"); + JFileSystem *fileSys = JFileSystem::GetInstance(); + if (!fileSys->OpenFile(filename)) + return; - //if(fp == NULL) - // return; - DWORD bkcol; - int result = image_readgif(fileSys, textureInfo, &bkcol, image_gif_read, mode); - if(result!=0) - textureInfo.mBits=NULL; - //fclose(fp); - fileSys->CloseFile(); - return ;//*/ + //if(fp == NULL) + // return; + DWORD bkcol; + int result = image_readgif(fileSys, textureInfo, &bkcol, image_gif_read, mode); + if(result!=0) + textureInfo.mBits=NULL; + //fclose(fp); + fileSys->CloseFile(); + return ;//*/ } #endif //(!defined IOS) && (!defined QT_CONFIG) && (!defined SDL_CONFIG) @@ -2154,15 +2163,15 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm do { if (!fileSystem->OpenFile(filename)) - break; + break; rawsize = fileSystem->GetFileSize(); rawdata = new BYTE[rawsize]; if (!rawdata) { - fileSystem->CloseFile(); - break; + fileSystem->CloseFile(); + break; } fileSystem->ReadFile(rawdata, rawsize); @@ -2177,8 +2186,8 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO); if (image == nil) { - NSLog(@"Loading Texture : %s failed", filename); - break; + NSLog(@"Loading Texture : %s failed", filename); + break; } textureInfo.mWidth = CGImageGetWidth(image.CGImage); @@ -2190,20 +2199,20 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm textureInfo.mBits = new u8 [ textureInfo.mTexHeight * textureInfo.mTexWidth * 4 ]; if (textureInfo.mBits == NULL) { - NSLog(@"Texture %s failed to load\n", filename); - break; + NSLog(@"Texture %s failed to load\n", filename); + break; } CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); info = /*hasAlpha ?*/ kCGImageAlphaPremultipliedLast /*: kCGImageAlphaNoneSkipLast*/; CGContextRef context = - CGBitmapContextCreate(textureInfo.mBits, - textureInfo.mTexWidth, - textureInfo.mTexHeight, 8, - 4 * textureInfo.mTexWidth, - colorSpace, - info /*| kCGBitmapByteOrder32Big*/); + CGBitmapContextCreate(textureInfo.mBits, + textureInfo.mTexWidth, + textureInfo.mTexHeight, 8, + 4 * textureInfo.mTexWidth, + colorSpace, + info /*| kCGBitmapByteOrder32Big*/); CGColorSpaceRelease(colorSpace); CGContextClearRect( context, CGRectMake( 0, 0, textureInfo.mTexWidth, textureInfo.mTexHeight ) ); CGContextTranslateCTM( context, 0, textureInfo.mTexHeight - textureInfo.mHeight ); @@ -2213,17 +2222,17 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm if (tex) { - if (mImageFilter != NULL) - mImageFilter->ProcessImage((PIXEL_TYPE*)textureInfo.mBits, textureInfo.mWidth, textureInfo.mHeight); + if (mImageFilter != NULL) + mImageFilter->ProcessImage((PIXEL_TYPE*)textureInfo.mBits, textureInfo.mWidth, textureInfo.mHeight); - tex->mFilter = TEX_FILTER_LINEAR; - tex->mWidth = textureInfo.mWidth; - tex->mHeight = textureInfo.mHeight; - tex->mTexWidth = textureInfo.mTexWidth; - tex->mTexHeight = textureInfo.mTexHeight; - tex->mBuffer = textureInfo.mBits; + tex->mFilter = TEX_FILTER_LINEAR; + tex->mWidth = textureInfo.mWidth; + tex->mHeight = textureInfo.mHeight; + tex->mTexWidth = textureInfo.mTexWidth; + tex->mTexHeight = textureInfo.mTexHeight; + tex->mBuffer = textureInfo.mBits; } else { - NSLog(@"JTexture for %s not created\n", filename); + NSLog(@"JTexture for %s not created\n", filename); } CGContextRelease(context); @@ -2240,58 +2249,58 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm #elif (defined QT_CONFIG) JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused))) { - JTexture *tex = NULL; - int rawsize = 0; - BYTE* rawdata = NULL; - JFileSystem* fileSystem = JFileSystem::GetInstance(); + JTexture *tex = NULL; + int rawsize = 0; + BYTE* rawdata = NULL; + JFileSystem* fileSystem = JFileSystem::GetInstance(); - do { - if (!fileSystem->OpenFile(filename)) - break; + do { + if (!fileSystem->OpenFile(filename)) + break; - rawsize = fileSystem->GetFileSize(); - rawdata = new BYTE[rawsize]; + rawsize = fileSystem->GetFileSize(); + rawdata = new BYTE[rawsize]; - if (!rawdata) - { - fileSystem->CloseFile(); - break; - } + if (!rawdata) + { + fileSystem->CloseFile(); + break; + } - fileSystem->ReadFile(rawdata, rawsize); - fileSystem->CloseFile(); + fileSystem->ReadFile(rawdata, rawsize); + fileSystem->CloseFile(); - QImage tmpImage = QImage::fromData(rawdata, rawsize); - if(tmpImage.isNull()) - break; + QImage tmpImage = QImage::fromData(rawdata, rawsize); + if(tmpImage.isNull()) + break; - tex = new JTexture(); - if (tex) - { - tmpImage = tmpImage.convertToFormat(QImage::Format_ARGB32_Premultiplied); - tmpImage = tmpImage.rgbSwapped(); + tex = new JTexture(); + if (tex) + { + tmpImage = tmpImage.convertToFormat(QImage::Format_ARGB32_Premultiplied); + tmpImage = tmpImage.rgbSwapped(); - if (mImageFilter != NULL) - mImageFilter->ProcessImage((PIXEL_TYPE*)tmpImage.bits(), tmpImage.width(), tmpImage.height()); + if (mImageFilter != NULL) + mImageFilter->ProcessImage((PIXEL_TYPE*)tmpImage.bits(), tmpImage.width(), tmpImage.height()); - tex->mFilter = TEX_FILTER_LINEAR; - tex->mWidth = tmpImage.width(); - tex->mHeight = tmpImage.height(); - tex->mTexWidth = getNextPower2(tmpImage.width()); - tex->mTexHeight = getNextPower2(tmpImage.height());; - tex->mBuffer = new BYTE[tex->mTexWidth*tex->mTexHeight*4]; + tex->mFilter = TEX_FILTER_LINEAR; + tex->mWidth = tmpImage.width(); + tex->mHeight = tmpImage.height(); + tex->mTexWidth = getNextPower2(tmpImage.width()); + tex->mTexHeight = getNextPower2(tmpImage.height());; + tex->mBuffer = new BYTE[tex->mTexWidth*tex->mTexHeight*4]; - for(int i=0; i < tex->mHeight; i++) - { - memcpy(tex->mBuffer+(i*4*tex->mTexWidth), tmpImage.constScanLine(i), tmpImage.bytesPerLine()); - } - } - } while(false); + for(int i=0; i < tex->mHeight; i++) + { + memcpy(tex->mBuffer+(i*4*tex->mTexWidth), tmpImage.constScanLine(i), tmpImage.bytesPerLine()); + } + } + } while(false); - if(rawdata) - delete[] rawdata; + if(rawdata) + delete[] rawdata; - return tex; + return tex; } #endif //IOS @@ -2381,7 +2390,7 @@ JTexture* JRenderer::CreateTexture(int width, int height, int mode __attribute__ delete[] buffer; - checkGlError(); + checkGlError(); } else @@ -2397,1359 +2406,1365 @@ JTexture* JRenderer::CreateTexture(int width, int height, int mode __attribute__ void JRenderer::EnableVSync(bool flag __attribute__((unused))) { -// if (flag) -// hge->System_SetState(HGE_FPS, 60); // HGEFPS_VSYNC -// else -// hge->System_SetState(HGE_FPS, HGEFPS_UNLIMITED); + // if (flag) + // hge->System_SetState(HGE_FPS, 60); // HGEFPS_VSYNC + // else + // hge->System_SetState(HGE_FPS, HGEFPS_UNLIMITED); } void JRenderer::ClearScreen(PIXEL_TYPE color) { - checkGlError(); - JColor col; - col.color = color; + checkGlError(); + static PIXEL_TYPE previousColor = RGBA(0xFF, 0xFF, 0xFF, 0xFF); + if (previousColor != color) + { + JColor col; + col.color = color; - glClearColor(col.r, col.g, col.b, col.a); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(col.r, col.g, col.b, col.a); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -// FillRect(0.0f, 0.0f, SCREEN_WIDTH_F, SCREEN_HEIGHT_F, color); - checkGlError(); + // FillRect(0.0f, 0.0f, SCREEN_WIDTH_F, SCREEN_HEIGHT_F, color); + checkGlError(); + + previousColor = color; + } } void JRenderer::SetTexBlend(int src, int dest) { - checkGlError(); - if (src != mCurrTexBlendSrc || dest != mCurrTexBlendDest) - { - mCurrTexBlendSrc = src; - mCurrTexBlendDest = dest; + checkGlError(); + if (src != mCurrTexBlendSrc || dest != mCurrTexBlendDest) + { + mCurrTexBlendSrc = src; + mCurrTexBlendDest = dest; - glBlendFunc(src, dest); - } - checkGlError(); + glBlendFunc(src, dest); + } + checkGlError(); } void JRenderer::SetTexBlendSrc(int src) { - checkGlError(); - if (src != mCurrTexBlendSrc) - { - mCurrTexBlendSrc = src; - glBlendFunc(mCurrTexBlendSrc, mCurrTexBlendDest); - } - checkGlError(); + checkGlError(); + if (src != mCurrTexBlendSrc) + { + mCurrTexBlendSrc = src; + glBlendFunc(mCurrTexBlendSrc, mCurrTexBlendDest); + } + checkGlError(); } void JRenderer::SetTexBlendDest(int dest) { - checkGlError(); - if (dest != mCurrTexBlendDest) - { - mCurrTexBlendDest = dest; - glBlendFunc(mCurrTexBlendSrc, mCurrTexBlendDest); - } - checkGlError(); + checkGlError(); + if (dest != mCurrTexBlendDest) + { + mCurrTexBlendDest = dest; + glBlendFunc(mCurrTexBlendSrc, mCurrTexBlendDest); + } + checkGlError(); } void JRenderer::Enable2D() { - checkGlError(); - if (mCurrentRenderMode == MODE_2D) - return; + checkGlError(); + if (mCurrentRenderMode == MODE_2D) + return; - mCurrentRenderMode = MODE_2D; + mCurrentRenderMode = MODE_2D; - glViewport (0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT); // Reset The Current Viewport + glViewport (0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT); // Reset The Current Viewport #if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - glMatrixMode (GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity (); // Reset The Projection Matrix + glMatrixMode (GL_PROJECTION); // Select The Projection Matrix + glLoadIdentity (); // Reset The Projection Matrix #if (defined GL_VERSION_ES_CM_1_1) - glOrthof(0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f, -1.0f, 1.0f); + glOrthof(0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f, -1.0f, 1.0f); #else - gluOrtho2D(0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f); + gluOrtho2D(0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f); #endif - glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity (); // Reset The Modelview Matrix + glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix + glLoadIdentity (); // Reset The Modelview Matrix #else - // all the matrix code is in shaders calls + // all the matrix code is in shaders calls #endif //(!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) - glDisable (GL_DEPTH_TEST); - checkGlError(); + glDisable (GL_DEPTH_TEST); + checkGlError(); } void JRenderer::Enable3D() { /* NOT USED - if (!m3DEnabled) - return; + if (!m3DEnabled) + return; - if (mCurrentRenderMode == MODE_3D) - return; + if (mCurrentRenderMode == MODE_3D) + return; - mCurrentRenderMode = MODE_3D; + mCurrentRenderMode = MODE_3D; - glViewport (0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT); // Reset The Current Viewport - glMatrixMode (GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity (); // Reset The Projection Matrix - gluPerspective (mFOV, (GLfloat)SCREEN_WIDTH/(GLfloat)SCREEN_HEIGHT, // Calculate The Aspect Ratio Of The Window - 0.5f, 1000.0f); - glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity (); // Reset The Modelview Matrix + glViewport (0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT); // Reset The Current Viewport + glMatrixMode (GL_PROJECTION); // Select The Projection Matrix + glLoadIdentity (); // Reset The Projection Matrix + gluPerspective (mFOV, (GLfloat)SCREEN_WIDTH/(GLfloat)SCREEN_HEIGHT, // Calculate The Aspect Ratio Of The Window + 0.5f, 1000.0f); + glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix + glLoadIdentity (); // Reset The Modelview Matrix - glEnable (GL_DEPTH_TEST); */ + glEnable (GL_DEPTH_TEST); */ } void JRenderer::SetClip(int x, int y, int width, int height) {// NOT USED - //glScissor(x, y, width, height); + //glScissor(x, y, width, height); } void JRenderer::LoadIdentity() {// NOT USED - //glLoadIdentity(); + //glLoadIdentity(); } void JRenderer::Translate(float x, float y, float z) {// NOT USED - //glTranslatef(x, y, z); + //glTranslatef(x, y, z); } void JRenderer::RotateX(float angle) {// NOT USED - //glRotatef(angle*RAD2DEG, 1.0f, 0.0f, 0.0f); + //glRotatef(angle*RAD2DEG, 1.0f, 0.0f, 0.0f); } void JRenderer::RotateY(float angle) {// NOT USED - //glRotatef(angle*RAD2DEG, 0.0f, 1.0f, 0.0f); + //glRotatef(angle*RAD2DEG, 0.0f, 1.0f, 0.0f); } void JRenderer::RotateZ(float angle) {// NOT USED - //glRotatef(angle*RAD2DEG, 0.0f, 0.0f, 1.0f); + //glRotatef(angle*RAD2DEG, 0.0f, 0.0f, 1.0f); } void JRenderer::PushMatrix() {// NOT USED - //glPushMatrix(); + //glPushMatrix(); } void JRenderer::PopMatrix() {// NOT USED - //glPopMatrix(); + //glPopMatrix(); } void JRenderer::RenderTriangles(JTexture* texture, Vertex3D *vertices, int start, int count) { - checkGlError(); - if (texture) - BindTexture(texture); + checkGlError(); + if (texture) + BindTexture(texture); - int index = start*3; + int index = start*3; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLubyte* colorCoords = new GLubyte[count*3*4]; - memset(colorCoords, 255, count*3*4); + GLubyte* colorCoords = new GLubyte[count*3*4]; + memset(colorCoords, 255, count*3*4); - // Use the program object - glUseProgram ( prog2 ); + // Use the program object + glUseProgram ( prog2 ); - // Load the vertex position - glVertexAttribPointer ( prog2_positionLoc, 3, GL_FLOAT, - GL_FALSE, 5 * sizeof(GLfloat), &vertices[index].x ); - // Load the texture coordinate - glVertexAttribPointer ( prog2_texCoordLoc, 2, GL_FLOAT, - GL_FALSE, 5 * sizeof(GLfloat), &vertices[index].u ); - // Load the colors - glVertexAttribPointer ( prog2_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colorCoords ); + // Load the vertex position + glVertexAttribPointer ( prog2_positionLoc, 3, GL_FLOAT, + GL_FALSE, 5 * sizeof(GLfloat), &vertices[index].x ); + // Load the texture coordinate + glVertexAttribPointer ( prog2_texCoordLoc, 2, GL_FLOAT, + GL_FALSE, 5 * sizeof(GLfloat), &vertices[index].u ); + // Load the colors + glVertexAttribPointer ( prog2_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colorCoords ); - glEnableVertexAttribArray ( prog2_positionLoc ); - glEnableVertexAttribArray ( prog2_texCoordLoc ); - glEnableVertexAttribArray ( prog2_colorLoc ); + glEnableVertexAttribArray ( prog2_positionLoc ); + glEnableVertexAttribArray ( prog2_texCoordLoc ); + glEnableVertexAttribArray ( prog2_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog2_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog2_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - // Bind the texture - glActiveTexture ( GL_TEXTURE0 ); - glBindTexture ( GL_TEXTURE_2D, mCurrentTex ); + // Bind the texture + glActiveTexture ( GL_TEXTURE0 ); + glBindTexture ( GL_TEXTURE_2D, mCurrentTex ); - // Set the sampler texture unit to 0 - glUniform1i ( prog2_samplerLoc, 0 ); + // Set the sampler texture unit to 0 + glUniform1i ( prog2_samplerLoc, 0 ); - glDrawArrays(GL_TRIANGLES,0,count*3); + glDrawArrays(GL_TRIANGLES,0,count*3); - delete[] colorCoords; + delete[] colorCoords; #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLubyte* colorCoords = new GLubyte[count*3*4]; - memset(colorCoords, 255, count*3*4); + GLubyte* colorCoords = new GLubyte[count*3*4]; + memset(colorCoords, 255, count*3*4); - glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), &vertices[index].x); - glTexCoordPointer(2,GL_FLOAT,5 * sizeof(GLfloat), &vertices[index].u); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); - glDrawArrays(GL_TRIANGLES,0,count*3); + glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), &vertices[index].x); + glTexCoordPointer(2,GL_FLOAT,5 * sizeof(GLfloat), &vertices[index].u); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorCoords ); + glDrawArrays(GL_TRIANGLES,0,count*3); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); - delete[] colorCoords; + delete[] colorCoords; #else - glBegin(GL_TRIANGLES); - for (int i = 0; i < count; i++) - { - glTexCoord2f(vertices[index].u, vertices[index].v); - //glNormal3f(vertices[index].nx, vertices[index].ny, vertices[index].nz); - glVertex3f(vertices[index].x, vertices[index].y, vertices[index].z); + glBegin(GL_TRIANGLES); + for (int i = 0; i < count; i++) + { + glTexCoord2f(vertices[index].u, vertices[index].v); + //glNormal3f(vertices[index].nx, vertices[index].ny, vertices[index].nz); + glVertex3f(vertices[index].x, vertices[index].y, vertices[index].z); - index++; + index++; - glTexCoord2f(vertices[index].u, vertices[index].v); - //glNormal3f(vertices[index].nx, vertices[index].ny, vertices[index].nz); - glVertex3f(vertices[index].x, vertices[index].y, vertices[index].z); + glTexCoord2f(vertices[index].u, vertices[index].v); + //glNormal3f(vertices[index].nx, vertices[index].ny, vertices[index].nz); + glVertex3f(vertices[index].x, vertices[index].y, vertices[index].z); - index++; + index++; - glTexCoord2f(vertices[index].u, vertices[index].v); - //glNormal3f(vertices[index].nx, vertices[index].ny, vertices[index].nz); - glVertex3f(vertices[index].x, vertices[index].y, vertices[index].z); + glTexCoord2f(vertices[index].u, vertices[index].v); + //glNormal3f(vertices[index].nx, vertices[index].ny, vertices[index].nz); + glVertex3f(vertices[index].x, vertices[index].y, vertices[index].z); - index++; - } - glEnd(); + index++; + } + glEnd(); #endif //#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::SetFOV(float fov) { - mFOV = fov; + mFOV = fov; } void JRenderer::FillPolygon(float* x, float* y, int count, PIXEL_TYPE color) { - checkGlError(); - JColor col; - col.color = color; - int i; + checkGlError(); + JColor col; + col.color = color; + int i; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLubyte* colors = new GLubyte[count*4]; - GLfloat* vVertices = new GLfloat[count*3]; + GLubyte* colors = new GLubyte[count*4]; + GLfloat* vVertices = new GLfloat[count*3]; - for(i = 0; i < count; i++) - { - colors[4*i+0]= col.r; - colors[4*i+1]= col.g; - colors[4*i+2]= col.b; - colors[4*i+3]= col.a; - } + for(i = 0; i < count; i++) + { + colors[4*i+0]= col.r; + colors[4*i+1]= col.g; + colors[4*i+2]= col.b; + colors[4*i+3]= col.a; + } - for(i=0; i < count;i++) - { - vVertices[3*i+0] = x[i]; - vVertices[3*i+1] = SCREEN_HEIGHT_F-y[i]; - vVertices[3*i+2] = 0.0f; - } + for(i=0; i < count;i++) + { + vVertices[3*i+0] = x[i]; + vVertices[3*i+1] = SCREEN_HEIGHT_F-y[i]; + vVertices[3*i+2] = 0.0f; + } - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colors); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colors); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_TRIANGLE_FAN,0,count); + glDrawArrays(GL_TRIANGLE_FAN,0,count); - delete[] vVertices; - delete[] colors; + delete[] vVertices; + delete[] colors; #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLubyte* colors = new GLubyte[count*4]; - GLfloat* vVertices = new GLfloat[count*3]; + GLubyte* colors = new GLubyte[count*4]; + GLfloat* vVertices = new GLfloat[count*3]; - for(i = 0; i < count; i++) - { - colors[4*i+0]= col.r; - colors[4*i+1]= col.g; - colors[4*i+2]= col.b; - colors[4*i+3]= col.a; - } + for(i = 0; i < count; i++) + { + colors[4*i+0]= col.r; + colors[4*i+1]= col.g; + colors[4*i+2]= col.b; + colors[4*i+3]= col.a; + } - for(i=0; i < count;i++) - { - vVertices[3*i+0] = x[i]; - vVertices[3*i+1] = SCREEN_HEIGHT_F-y[i]; - vVertices[3*i+2] = 0.0f; - } + for(i=0; i < count;i++) + { + vVertices[3*i+0] = x[i]; + vVertices[3*i+1] = SCREEN_HEIGHT_F-y[i]; + vVertices[3*i+2] = 0.0f; + } - glVertexPointer(3, GL_FLOAT, 0, vVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); - glDrawArrays(GL_TRIANGLE_FAN,0,count); + glVertexPointer(3, GL_FLOAT, 0, vVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); + glDrawArrays(GL_TRIANGLE_FAN,0,count); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); - delete[] vVertices; - delete[] colors; + delete[] vVertices; + delete[] colors; #else - glDisable(GL_TEXTURE_2D); - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_TRIANGLE_FAN); + glDisable(GL_TEXTURE_2D); + glColor4ub(col.r, col.g, col.b, col.a); + glBegin(GL_TRIANGLE_FAN); - for(i=0; i= 360.0f) - angle -= 360.0f; - } + for(i=0; i= 360.0f) + angle -= 360.0f; + } - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colors); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colors); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_LINE_LOOP,0,count); + glDrawArrays(GL_LINE_LOOP,0,count); - delete[] vVertices; - delete[] colors; + delete[] vVertices; + delete[] colors; #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat* vVertices = new GLfloat[3*count]; - GLubyte* colors = new GLubyte[4*count]; + GLfloat* vVertices = new GLfloat[3*count]; + GLubyte* colors = new GLubyte[4*count]; - for(i = 0; i < count; i++) - { - colors[4*i+0]= col.r; - colors[4*i+1]= col.g; - colors[4*i+2]= col.b; - colors[4*i+3]= col.a; - } - - for(i=0; i= 360.0f) - angle -= 360.0f; - } - - glVertexPointer(3, GL_FLOAT, 0, vVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); - glDrawArrays(GL_LINE_LOOP,0,count); - - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - - delete[] vVertices; - delete[] colors; - -#else - glDisable(GL_TEXTURE_2D); - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_LINE_LOOP); + for(i = 0; i < count; i++) + { + colors[4*i+0]= col.r; + colors[4*i+1]= col.g; + colors[4*i+2]= col.b; + colors[4*i+3]= col.a; + } for(i=0; i= 360.0f) + angle -= 360.0f; + } - angle += steps; - if (angle >= 360.0f) - angle -= 360.0f; - } + glVertexPointer(3, GL_FLOAT, 0, vVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); + glDrawArrays(GL_LINE_LOOP,0,count); - glEnd(); - // default color - glColor4ub(255, 255, 255, 255); - glEnable(GL_TEXTURE_2D); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + + delete[] vVertices; + delete[] colors; + +#else + glDisable(GL_TEXTURE_2D); + glColor4ub(col.r, col.g, col.b, col.a); + glBegin(GL_LINE_LOOP); + + for(i=0; i= 360.0f) + angle -= 360.0f; + } + + glEnd(); + // default color + glColor4ub(255, 255, 255, 255); + glEnable(GL_TEXTURE_2D); #endif //#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::FillPolygon(float x, float y, float size, int count, float startingAngle, PIXEL_TYPE color) { - checkGlError(); - JColor col; - col.color = color; + checkGlError(); + JColor col; + col.color = color; - float angle = startingAngle*RAD2DEG; - float firstAngle = angle; - float steps = 360.0f/count; - size /= 2; - int i; + float angle = startingAngle*RAD2DEG; + float firstAngle = angle; + float steps = 360.0f/count; + size /= 2; + int i; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - GLfloat* vVertices = new GLfloat[3*(count+2)]; - GLubyte* colors = new GLubyte[4*(count+2)]; + GLfloat* vVertices = new GLfloat[3*(count+2)]; + GLubyte* colors = new GLubyte[4*(count+2)]; - for(i = 0; i < count+2; i++) - { - colors[4*i+0]= col.r; - colors[4*i+1]= col.g; - colors[4*i+2]= col.b; - colors[4*i+3]= col.a; - } + for(i = 0; i < count+2; i++) + { + colors[4*i+0]= col.r; + colors[4*i+1]= col.g; + colors[4*i+2]= col.b; + colors[4*i+3]= col.a; + } - vVertices[0] = x; - vVertices[1] = SCREEN_HEIGHT_F-y; - vVertices[2] = 0.0f; + vVertices[0] = x; + vVertices[1] = SCREEN_HEIGHT_F-y; + vVertices[2] = 0.0f; - for(i=1; i= 360.0f) - angle -= 360.0f; - } + for(i=1; i= 360.0f) + angle -= 360.0f; + } - vVertices[3*(1+count)+0] = x+size*COSF((int)firstAngle); - vVertices[3*(1+count)+1] = SCREEN_HEIGHT_F-y+size*SINF((int)firstAngle); - vVertices[3*(1+count)+2] = 0.0f; + vVertices[3*(1+count)+0] = x+size*COSF((int)firstAngle); + vVertices[3*(1+count)+1] = SCREEN_HEIGHT_F-y+size*SINF((int)firstAngle); + vVertices[3*(1+count)+2] = 0.0f; - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colors); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colors); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_TRIANGLE_FAN,0,count+2); + glDrawArrays(GL_TRIANGLE_FAN,0,count+2); - delete[] vVertices; - delete[] colors; + delete[] vVertices; + delete[] colors; #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - GLfloat* vVertices = new GLfloat[3*(count+2)]; - GLubyte* colors = new GLubyte[4*(count+2)]; + GLfloat* vVertices = new GLfloat[3*(count+2)]; + GLubyte* colors = new GLubyte[4*(count+2)]; - for(i = 0; i < count+2; i++) - { - colors[4*i+0]= col.r; - colors[4*i+1]= col.g; - colors[4*i+2]= col.b; - colors[4*i+3]= col.a; - } + for(i = 0; i < count+2; i++) + { + colors[4*i+0]= col.r; + colors[4*i+1]= col.g; + colors[4*i+2]= col.b; + colors[4*i+3]= col.a; + } - vVertices[0] = x; - vVertices[1] = SCREEN_HEIGHT_F-y; - vVertices[2] = 0.0f; + vVertices[0] = x; + vVertices[1] = SCREEN_HEIGHT_F-y; + vVertices[2] = 0.0f; - for(i=1; i= 360.0f) - angle -= 360.0f; - } + for(i=1; i= 360.0f) + angle -= 360.0f; + } - vVertices[3*(1+count)+0] = x+size*COSF((int)firstAngle); - vVertices[3*(1+count)+1] = SCREEN_HEIGHT_F-y+size*SINF((int)firstAngle); - vVertices[3*(1+count)+2] = 0.0f; + vVertices[3*(1+count)+0] = x+size*COSF((int)firstAngle); + vVertices[3*(1+count)+1] = SCREEN_HEIGHT_F-y+size*SINF((int)firstAngle); + vVertices[3*(1+count)+2] = 0.0f; - glVertexPointer(3, GL_FLOAT, 0, vVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); - glDrawArrays(GL_TRIANGLE_FAN,0,count+2); + glVertexPointer(3, GL_FLOAT, 0, vVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); + glDrawArrays(GL_TRIANGLE_FAN,0,count+2); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); - delete[] vVertices; - delete[] colors; + delete[] vVertices; + delete[] colors; #else - glDisable(GL_TEXTURE_2D); - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_TRIANGLE_FAN); + glDisable(GL_TEXTURE_2D); + glColor4ub(col.r, col.g, col.b, col.a); + glBegin(GL_TRIANGLE_FAN); - glVertex2f(x, SCREEN_HEIGHT_F-y); + glVertex2f(x, SCREEN_HEIGHT_F-y); for(i=0; i= 360.0f) - angle -= 360.0f; - } + { + glVertex2f(x+size*COSF((int)angle), SCREEN_HEIGHT_F-y+size*SINF((int)angle)); + angle += steps; + if (angle >= 360.0f) + angle -= 360.0f; + } - glVertex2f(x+size*COSF((int)firstAngle), SCREEN_HEIGHT_F-y+size*SINF((int)firstAngle)); + glVertex2f(x+size*COSF((int)firstAngle), SCREEN_HEIGHT_F-y+size*SINF((int)firstAngle)); - glEnd(); + glEnd(); - // default color - glColor4ub(255, 255, 255, 255); - glEnable(GL_TEXTURE_2D); + // default color + glColor4ub(255, 255, 255, 255); + glEnable(GL_TEXTURE_2D); #endif //#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - checkGlError(); + checkGlError(); } void JRenderer::SetImageFilter(JImageFilter* imageFilter) { - mImageFilter = imageFilter; + mImageFilter = imageFilter; } void JRenderer::DrawRoundRect(float x, float y, float w, float h, float radius, PIXEL_TYPE color) { - checkGlError(); - x+=w+radius; - y+=h+radius; - JColor col; - col.color = color; - int i; + checkGlError(); + x+=w+radius; + y+=h+radius; + JColor col; + col.color = color; + int i; #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) - int number = 360; - GLfloat* vVertices = new GLfloat[3*number]; - GLubyte* colors = new GLubyte[4*number]; + int number = 360; + GLfloat* vVertices = new GLfloat[3*number]; + GLubyte* colors = new GLubyte[4*number]; - for(i = 0; i < number; i++) - { - colors[4*i+0]= col.r; - colors[4*i+1]= col.g; - colors[4*i+2]= col.b; - colors[4*i+3]= col.a; - } + for(i = 0; i < number; i++) + { + colors[4*i+0]= col.r; + colors[4*i+1]= col.g; + colors[4*i+2]= col.b; + colors[4*i+3]= col.a; + } - for(i=0; i<90;i++) { - vVertices[3 * i + 0] = x+radius*COSF(i); - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); - vVertices[3 * i + 2] = 0.0f; - } + for(i=0; i<90;i++) { + vVertices[3 * i + 0] = x+radius*COSF(i); + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); + vVertices[3 * i + 2] = 0.0f; + } - for(i=90; i<180;i++) - { - vVertices[3 * i + 0] = x+radius*COSF(i)-w; - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); - vVertices[3 * i + 2] = 0.0f; - } + for(i=90; i<180;i++) + { + vVertices[3 * i + 0] = x+radius*COSF(i)-w; + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); + vVertices[3 * i + 2] = 0.0f; + } - for(i=180; i<270;i++) - { - vVertices[3 * i + 0] = x+radius*COSF(i)-w; - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); - vVertices[3 * i + 2] = 0.0f; - } + for(i=180; i<270;i++) + { + vVertices[3 * i + 0] = x+radius*COSF(i)-w; + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); + vVertices[3 * i + 2] = 0.0f; + } - for(i=270; i<360;i++) - { - vVertices[3 * i + 0] = x+radius*COSF(i); - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); - vVertices[3 * i + 2] = 0.0f; - } + for(i=270; i<360;i++) + { + vVertices[3 * i + 0] = x+radius*COSF(i); + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); + vVertices[3 * i + 2] = 0.0f; + } - // Use the program object without texture - glUseProgram ( prog1 ); + // Use the program object without texture + glUseProgram ( prog1 ); - // Load the vertex position - glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), vVertices ); - // Load the color - glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, - GL_TRUE, 4 * sizeof(GLubyte), colors); + // Load the vertex position + glVertexAttribPointer ( prog1_positionLoc, 3, GL_FLOAT, + GL_FALSE, 3 * sizeof(GLfloat), vVertices ); + // Load the color + glVertexAttribPointer(prog1_colorLoc, 4, GL_UNSIGNED_BYTE, + GL_TRUE, 4 * sizeof(GLubyte), colors); - glEnableVertexAttribArray ( prog1_positionLoc ); - glEnableVertexAttribArray ( prog1_colorLoc ); + glEnableVertexAttribArray ( prog1_positionLoc ); + glEnableVertexAttribArray ( prog1_colorLoc ); - // Load the MVP matrix - glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); + // Load the MVP matrix + glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] ); - glDrawArrays(GL_LINE_LOOP,0,number); + glDrawArrays(GL_LINE_LOOP,0,number); - delete[] vVertices; - delete[] colors; + delete[] vVertices; + delete[] colors; #elif (defined GL_VERSION_ES_CM_1_1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - int number = 360; - GLfloat* vVertices = new GLfloat[3*number]; - GLubyte* colors = new GLubyte[4*number]; + int number = 360; + GLfloat* vVertices = new GLfloat[3*number]; + GLubyte* colors = new GLubyte[4*number]; - for(i = 0; i < number; i++) - { - colors[4*i+0]= col.r; - colors[4*i+1]= col.g; - colors[4*i+2]= col.b; - colors[4*i+3]= col.a; - } + for(i = 0; i < number; i++) + { + colors[4*i+0]= col.r; + colors[4*i+1]= col.g; + colors[4*i+2]= col.b; + colors[4*i+3]= col.a; + } - for(i=0; i<90;i++) { - vVertices[3 * i + 0] = x+radius*COSF(i); - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); - vVertices[3 * i + 2] = 0.0f; - } + for(i=0; i<90;i++) { + vVertices[3 * i + 0] = x+radius*COSF(i); + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); + vVertices[3 * i + 2] = 0.0f; + } - for(i=90; i<180;i++) - { - vVertices[3 * i + 0] = x+radius*COSF(i)-w; - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); - vVertices[3 * i + 2] = 0.0f; - } + for(i=90; i<180;i++) + { + vVertices[3 * i + 0] = x+radius*COSF(i)-w; + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)); + vVertices[3 * i + 2] = 0.0f; + } - for(i=180; i<270;i++) - { - vVertices[3 * i + 0] = x+radius*COSF(i)-w; - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); - vVertices[3 * i + 2] = 0.0f; - } + for(i=180; i<270;i++) + { + vVertices[3 * i + 0] = x+radius*COSF(i)-w; + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); + vVertices[3 * i + 2] = 0.0f; + } - for(i=270; i<360;i++) - { - vVertices[3 * i + 0] = x+radius*COSF(i); - vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); - vVertices[3 * i + 2] = 0.0f; - } + for(i=270; i<360;i++) + { + vVertices[3 * i + 0] = x+radius*COSF(i); + vVertices[3 * i + 1] = SCREEN_HEIGHT_F-(y+radius*SINF(i)-h); + vVertices[3 * i + 2] = 0.0f; + } - glVertexPointer(3, GL_FLOAT, 0, vVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); - glDrawArrays(GL_LINE_LOOP,0,number); + glVertexPointer(3, GL_FLOAT, 0, vVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors ); + glDrawArrays(GL_LINE_LOOP,0,number); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); - delete[] vVertices; - delete[] colors; + delete[] vVertices; + delete[] colors; #else - glDisable(GL_TEXTURE_2D); - glColor4ub(col.r, col.g, col.b, col.a); - glBegin(GL_LINE_LOOP); + glDisable(GL_TEXTURE_2D); + glColor4ub(col.r, col.g, col.b, col.a); + glBegin(GL_LINE_LOOP); - for(i=0; i<90;i++) - { - glVertex2f(x+radius*COSF(i), SCREEN_HEIGHT_F-(y+radius*SINF(i))); - } - for(i=0; i