- Defined keys translation for SDL config
- Added boost thread files, that fixes all the threading/compiling/linking problems on Android ... - Added opengles 1.1 code, there are still some bugs I need to tackle ... and I should realy split this file now !!! - Added Android debug traces - Hardcoded resources to "/sdcard/Wagic/Res" for the moment on Android - Added a wagic SDL project for desktop, and the related SDL frontend used for Android. This frontend is currently mostly desktop based, it needs some work to be fully useable with touch and gesture on Android.
This commit is contained in:
@@ -25,27 +25,34 @@ std::string ToHex(T* pointer)
|
||||
#define OutputDebugString(val) (std::cerr << val);
|
||||
#endif
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
#ifdef _DEBUG
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
|
||||
#ifndef QT_CONFIG
|
||||
#ifdef QT_CONFIG
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
OutputDebugString(stream.str().c_str()); \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
qDebug(stream.str().c_str()); \
|
||||
}
|
||||
#elif defined (ANDROID)
|
||||
#include <android/log.h>
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString; \
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "Wagic", stream.str().c_str());\
|
||||
}
|
||||
#else
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
qDebug(stream.str().c_str()); \
|
||||
OutputDebugString(stream.str().c_str()); \
|
||||
}
|
||||
#endif //QT_CONFIG
|
||||
|
||||
#endif //#ifdef _DEBUG
|
||||
#endif // QT_CONFIG
|
||||
#endif // Win32, Linux
|
||||
#endif //#ifdef _DEBUG
|
||||
|
||||
#if defined (DEBUG)
|
||||
#ifndef DebugTrace
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
typedef u32 LocalKeySym;
|
||||
#define LOCAL_KEY_NONE Qt::Key_unknown
|
||||
|
||||
#elif defined(SDL_CONFIG)
|
||||
#include <SDL.h>
|
||||
typedef SDLKey LocalKeySym;
|
||||
#define LOCAL_KEY_NONE SDLK_UNKNOWN
|
||||
|
||||
#elif defined(WIN32)
|
||||
#include <windows.h>
|
||||
typedef WPARAM LocalKeySym;
|
||||
@@ -50,7 +55,6 @@ typedef u32 LocalKeySym;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
bool JGEGetButtonState(const JButton button);
|
||||
bool JGEGetButtonClick(const JButton button);
|
||||
void JGECreateDefaultBindings();
|
||||
|
||||
@@ -101,22 +101,13 @@ enum {
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
# import <OpenGLES/ES1/glext.h>
|
||||
# import <OpenGLES/ES1/glext.h>
|
||||
#elif defined (ANDROID)
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
#elif defined (WIN32) || defined (LINUX)
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
//Android GL1 support TODO
|
||||
/*
|
||||
#elif defined (ANDROID)
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
*/
|
||||
//Android GL2 support
|
||||
#elif defined (ANDROID)
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#endif
|
||||
#else
|
||||
# include <QtOpenGL>
|
||||
|
||||
@@ -269,6 +269,8 @@ void JFileSystem::SetResourceRoot(const string& resourceRoot)
|
||||
NSString *fullpath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pathUTF8];
|
||||
mResourceRoot = [fullpath cStringUsingEncoding:1];
|
||||
mResourceRoot += "/";
|
||||
#elif defined (ANDROID)
|
||||
mResourceRoot = "/sdcard/Wagic/Res/";
|
||||
#else
|
||||
mResourceRoot = resourceRoot;
|
||||
#endif
|
||||
|
||||
448
JGE/src/SDLmain.cpp
Normal file
448
JGE/src/SDLmain.cpp
Normal file
@@ -0,0 +1,448 @@
|
||||
#include <SDL.h>
|
||||
#ifndef ANDROID
|
||||
#include <SDL_opengl.h>
|
||||
#else
|
||||
#include <SDL_opengles.h>
|
||||
#endif
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JTypes.h"
|
||||
#include "../include/JApp.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JGameLauncher.h"
|
||||
#include "DebugRoutines.h"
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#undef GL_VERSION_2_0
|
||||
|
||||
#define ACTUAL_SCREEN_WIDTH (SCREEN_WIDTH)
|
||||
#define ACTUAL_SCREEN_HEIGHT (SCREEN_HEIGHT)
|
||||
#define ACTUAL_RATIO ((GLfloat)ACTUAL_SCREEN_WIDTH / (GLfloat)ACTUAL_SCREEN_HEIGHT)
|
||||
|
||||
#define WAGIC_UPDATE_EVENT (SDL_USEREVENT + 1)
|
||||
|
||||
class SdlApp {
|
||||
private:
|
||||
bool Running;
|
||||
SDL_Surface* Surf_Display;
|
||||
SDL_Rect viewPort;
|
||||
|
||||
public:
|
||||
SdlApp() {
|
||||
Surf_Display = NULL;
|
||||
|
||||
Running = true;
|
||||
};
|
||||
|
||||
int OnExecute() {
|
||||
if(OnInit() == false) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Event Event;
|
||||
|
||||
while(Running) {
|
||||
while(SDL_PollEvent(&Event)) {
|
||||
OnEvent(&Event);
|
||||
}
|
||||
|
||||
OnLoop();
|
||||
// OnRender();
|
||||
}
|
||||
|
||||
OnCleanup();
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
public:
|
||||
bool OnInit();
|
||||
|
||||
void OnResize(int width, int height) {
|
||||
if ((GLfloat)width / (GLfloat)height <= ACTUAL_RATIO)
|
||||
{
|
||||
viewPort.x = 0;
|
||||
viewPort.y = -((width/ACTUAL_RATIO)-height)/2;
|
||||
viewPort.w = width;
|
||||
viewPort.h = width / ACTUAL_RATIO;
|
||||
}
|
||||
else
|
||||
{
|
||||
viewPort.x = -(height*ACTUAL_RATIO-width)/2;
|
||||
viewPort.y = 0;
|
||||
viewPort.w = height * ACTUAL_RATIO;
|
||||
viewPort.h = height;
|
||||
}
|
||||
|
||||
glViewport(viewPort.x, viewPort.y, viewPort.w, viewPort.h);
|
||||
|
||||
JRenderer::GetInstance()->SetActualWidth(viewPort.w);
|
||||
JRenderer::GetInstance()->SetActualHeight(viewPort.h);
|
||||
glScissor(0, 0, width, height);
|
||||
|
||||
#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
|
||||
|
||||
glMatrixMode (GL_PROJECTION); // Select The Projection Matrix
|
||||
glLoadIdentity (); // Reset The Projection Matrix
|
||||
|
||||
//gluOrtho2D(0.0f, (float) (viewPort.w)-1.0f, 0.0f, (float) (viewPort.h)-1.0f);
|
||||
|
||||
#if (defined GL_VERSION_ES_CM_1_1)
|
||||
glOrthof(0.0f, (float) (viewPort.w)-1.0f, 0.0f, (float) (viewPort.h)-1.0f, -1.0f, 1.0f);
|
||||
#else
|
||||
gluOrtho2D(0.0f, (float) (viewPort.w)-1.0f, 0.0f, (float) (viewPort.h)-1.0f);
|
||||
#endif
|
||||
glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
|
||||
glLoadIdentity (); // Reset The Modelview Matrix
|
||||
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
|
||||
#endif
|
||||
};
|
||||
void OnKeyPressed(const SDL_KeyboardEvent& event);
|
||||
void OnMouseClicked(const SDL_MouseButtonEvent& event);
|
||||
void OnMouseMoved(const SDL_MouseMotionEvent& event);
|
||||
void OnEvent(SDL_Event* Event) {
|
||||
switch(Event->type){
|
||||
case SDL_QUIT:
|
||||
Running = false;
|
||||
break;
|
||||
case SDL_VIDEORESIZE:
|
||||
OnResize(Event->resize.w, Event->resize.h);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
OnKeyPressed(Event->key);
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
OnMouseMoved(Event->motion);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
OnMouseClicked(Event->button);
|
||||
break;
|
||||
case WAGIC_UPDATE_EVENT:
|
||||
OnUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
void OnUpdate();
|
||||
void OnRender();
|
||||
void OnLoop() {
|
||||
};
|
||||
|
||||
void OnCleanup() {
|
||||
SDL_FreeSurface(Surf_Display);
|
||||
SDL_Quit();
|
||||
}
|
||||
};
|
||||
|
||||
uint64_t lastTickCount;
|
||||
JGE* g_engine = NULL;
|
||||
JApp* g_app = NULL;
|
||||
JGameLauncher* g_launcher = NULL;
|
||||
SdlApp *g_SdlApp = NULL;
|
||||
|
||||
|
||||
|
||||
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
||||
{
|
||||
{ SDLK_RETURN, JGE_BTN_MENU },
|
||||
{ SDLK_KP_ENTER, JGE_BTN_MENU },
|
||||
{ SDLK_ESCAPE, JGE_BTN_MENU },
|
||||
{ SDLK_BACKSPACE, JGE_BTN_CTRL },
|
||||
{ SDLK_UP, JGE_BTN_UP },
|
||||
{ SDLK_DOWN, JGE_BTN_DOWN },
|
||||
{ SDLK_LEFT, JGE_BTN_LEFT },
|
||||
{ SDLK_RIGHT, JGE_BTN_RIGHT },
|
||||
{ SDLK_SPACE, JGE_BTN_OK },
|
||||
{ SDLK_TAB, JGE_BTN_CANCEL },
|
||||
{ SDLK_j, JGE_BTN_PRI },
|
||||
{ SDLK_k, JGE_BTN_SEC },
|
||||
{ SDLK_q, JGE_BTN_PREV },
|
||||
{ SDLK_a, JGE_BTN_NEXT },
|
||||
// fullscreen management seems somehow broken in JGE, it works fine with Qt directly
|
||||
// { Qt::Key_F, JGE_BTN_FULLSCREEN },
|
||||
};
|
||||
|
||||
void JGECreateDefaultBindings()
|
||||
{
|
||||
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
|
||||
g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
|
||||
}
|
||||
|
||||
int JGEGetTime()
|
||||
{
|
||||
return (int)SDL_GetTicks();
|
||||
}
|
||||
|
||||
bool JGEToggleFullscreen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InitGame(void)
|
||||
{
|
||||
g_engine = JGE::GetInstance();
|
||||
g_app = g_launcher->GetGameApp();
|
||||
g_app->Create();
|
||||
g_engine->SetApp(g_app);
|
||||
|
||||
JRenderer::GetInstance()->Enable2D();
|
||||
lastTickCount = JGEGetTime();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DestroyGame(void)
|
||||
{
|
||||
g_engine->SetApp(NULL);
|
||||
if (g_app)
|
||||
{
|
||||
g_app->Destroy();
|
||||
delete g_app;
|
||||
g_app = NULL;
|
||||
}
|
||||
|
||||
JGE::Destroy();
|
||||
|
||||
g_engine = NULL;
|
||||
}
|
||||
|
||||
Uint32 OnTimer( Uint32 interval )
|
||||
{
|
||||
SDL_Event event;
|
||||
event.user.type = WAGIC_UPDATE_EVENT;
|
||||
SDL_PushEvent(&event);
|
||||
return 30;
|
||||
}
|
||||
|
||||
void SdlApp::OnUpdate() {
|
||||
static int tickCount;
|
||||
Uint32 dt;
|
||||
tickCount = JGEGetTime();
|
||||
dt = (tickCount - lastTickCount);
|
||||
lastTickCount = tickCount;
|
||||
|
||||
if(g_engine->IsDone()) {
|
||||
SDL_Event event;
|
||||
event.user.type = SDL_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
try {
|
||||
g_engine->SetDelta((float)dt / 1000.0f);
|
||||
g_engine->Update((float)dt / 1000.0f);
|
||||
} catch(out_of_range& oor) {
|
||||
cerr << oor.what();
|
||||
}
|
||||
|
||||
OnRender();
|
||||
}
|
||||
|
||||
void SdlApp::OnKeyPressed(const SDL_KeyboardEvent& event)
|
||||
{
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
g_engine->HoldKey_NoRepeat((LocalKeySym)event.keysym.sym);
|
||||
} else if(event.type == SDL_KEYUP) {
|
||||
g_engine->ReleaseKey((LocalKeySym)event.keysym.sym);
|
||||
}
|
||||
}
|
||||
|
||||
void SdlApp::OnMouseMoved(const SDL_MouseMotionEvent& event)
|
||||
{
|
||||
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
||||
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
||||
|
||||
if (event.y >= viewPort.y &&
|
||||
event.y <= viewPort.y + viewPort.h &&
|
||||
event.x >= viewPort.x &&
|
||||
event.x <= viewPort.x + viewPort.w) {
|
||||
g_engine->LeftClicked(
|
||||
((event.x-viewPort.x)*SCREEN_WIDTH)/actualWidth,
|
||||
((event.y-viewPort.y)*SCREEN_HEIGHT)/actualHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void SdlApp::OnMouseClicked(const SDL_MouseButtonEvent& event)
|
||||
{
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if(event.button == SDL_BUTTON_LEFT) /* Left button */
|
||||
{
|
||||
// this is intended to convert window coordinate into game coordinate.
|
||||
// this is correct only if the game and window have the same aspect ratio, otherwise, it's just wrong
|
||||
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
||||
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
||||
|
||||
if (event.y >= viewPort.y &&
|
||||
event.y <= viewPort.y + viewPort.h &&
|
||||
event.x >= viewPort.x &&
|
||||
event.x <= viewPort.x + viewPort.w) {
|
||||
g_engine->LeftClicked(
|
||||
((event.x-viewPort.x)*SCREEN_WIDTH)/actualWidth,
|
||||
((event.y-viewPort.y)*SCREEN_HEIGHT)/actualHeight);
|
||||
g_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
||||
} else if(event.y < viewPort.y) {
|
||||
g_engine->HoldKey_NoRepeat(JGE_BTN_MENU);
|
||||
} else if(event.y > viewPort.y + viewPort.h) {
|
||||
g_engine->HoldKey_NoRepeat(JGE_BTN_NEXT);
|
||||
}
|
||||
}
|
||||
else if(event.button == SDL_BUTTON_RIGHT) /* Right button */
|
||||
{ /* next phase please */
|
||||
g_engine->HoldKey_NoRepeat(JGE_BTN_PREV);
|
||||
}
|
||||
else if(event.button == SDL_BUTTON_MIDDLE) /* Middle button */
|
||||
{ /* interrupt please */
|
||||
g_engine->HoldKey_NoRepeat(JGE_BTN_SEC);
|
||||
}
|
||||
} else if (event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(event.button == SDL_BUTTON_LEFT)
|
||||
{
|
||||
if (event.y >= viewPort.y &&
|
||||
event.y <= viewPort.y + viewPort.h &&
|
||||
event.x >= viewPort.x &&
|
||||
event.x <= viewPort.x + viewPort.w) {
|
||||
g_engine->ReleaseKey(JGE_BTN_OK);
|
||||
} else if(event.y < viewPort.y) {
|
||||
g_engine->ReleaseKey(JGE_BTN_MENU);
|
||||
} else if(event.y > viewPort.y + viewPort.h) {
|
||||
g_engine->ReleaseKey(JGE_BTN_NEXT);
|
||||
}
|
||||
}
|
||||
else if(event.button == SDL_BUTTON_RIGHT)
|
||||
{ /* next phase please */
|
||||
g_engine->ReleaseKey(JGE_BTN_PREV);
|
||||
}
|
||||
else if(event.button == SDL_BUTTON_MIDDLE)
|
||||
{ /* interrupt please */
|
||||
g_engine->ReleaseKey(JGE_BTN_SEC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SdlApp::OnInit() {
|
||||
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
|
||||
|
||||
if((Surf_Display = SDL_SetVideoMode(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT, 32, /*SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER |*/ SDL_OPENGL | SDL_RESIZABLE)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption(g_launcher->GetName(), "");
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers)
|
||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
||||
#if (defined GL_ES_VERSION_2_0)
|
||||
glClearDepthf(1.0f); // Depth Buffer Setup
|
||||
#else
|
||||
glClearDepth(1.0f); // Depth Buffer Setup
|
||||
#endif// (defined GL_ES_VERSION_2_0)
|
||||
|
||||
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
|
||||
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
|
||||
|
||||
#else
|
||||
#if (defined GL_VERSION_ES_CM_1_1)
|
||||
glClearDepthf(1.0f); // Depth Buffer Setup
|
||||
#else
|
||||
glClearDepth(1.0f); // Depth Buffer Setup
|
||||
#endif
|
||||
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
|
||||
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
|
||||
glShadeModel(GL_SMOOTH); // Select Smooth Shading
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
|
||||
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Set Line Antialiasing
|
||||
glEnable(GL_LINE_SMOOTH); // Enable it!
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
#endif
|
||||
|
||||
glEnable(GL_CULL_FACE); // do not calculate inside of poly's
|
||||
glFrontFace(GL_CCW); // counter clock-wise polygons are out
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glEnable(GL_SCISSOR_TEST); // Enable Clipping
|
||||
|
||||
|
||||
OnResize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT);
|
||||
|
||||
/* opengl needs to be fully initialized before starting the game */
|
||||
if (!InitGame())
|
||||
{
|
||||
cerr << "Could not init the game\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
JGECreateDefaultBindings();
|
||||
|
||||
SDL_SetTimer(5, OnTimer);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
void SdlApp::OnRender() {
|
||||
|
||||
if(g_engine)
|
||||
g_engine->Render();
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
};
|
||||
|
||||
|
||||
#ifdef ANDROID
|
||||
int SDL_main(int argc, char * argv[])
|
||||
#else
|
||||
int main(int argc, char* argv[])
|
||||
#endif //ANDROID
|
||||
{
|
||||
DebugTrace("I R in da native");
|
||||
|
||||
g_launcher = new JGameLauncher();
|
||||
|
||||
u32 flags = g_launcher->GetInitFlags();
|
||||
|
||||
if ((flags&JINIT_FLAG_ENABLE3D)!=0)
|
||||
{
|
||||
JRenderer::Set3DFlag(true);
|
||||
}
|
||||
|
||||
g_SdlApp = new SdlApp();
|
||||
|
||||
int result = g_SdlApp->OnExecute();
|
||||
|
||||
if (g_launcher)
|
||||
delete g_launcher;
|
||||
|
||||
if(g_SdlApp)
|
||||
delete g_SdlApp;
|
||||
|
||||
// Shutdown
|
||||
DestroyGame();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#if (!defined IOS)
|
||||
#if (!defined IOS) && (!defined QT_CONFIG)
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4786)
|
||||
#pragma comment( lib, "giflib.lib" )
|
||||
@@ -42,12 +42,18 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define checkGlError() \
|
||||
void checkGlError()
|
||||
{
|
||||
GLenum glError = glGetError();
|
||||
if(glError != 0)
|
||||
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); \
|
||||
}
|
||||
}/*/
|
||||
#else
|
||||
#define checkGlError() (void(0))
|
||||
#endif
|
||||
@@ -955,32 +961,44 @@ void JRenderer::RenderQuad(JQuad* quad, float xo, float yo, float angle, float x
|
||||
|
||||
// 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();
|
||||
|
||||
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();
|
||||
|
||||
// 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();
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
|
||||
checkGlError();
|
||||
|
||||
#else
|
||||
glPushMatrix();
|
||||
@@ -988,7 +1006,7 @@ void JRenderer::RenderQuad(JQuad* quad, float xo, float yo, float angle, float x
|
||||
glRotatef(-angle*RAD2DEG, 0.0f, 0.0f, 1.0f);
|
||||
glScalef(xScale, yScale, 1.0f);
|
||||
|
||||
#if (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1)
|
||||
#if (defined GL_VERSION_ES_CM_1_1)
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
@@ -1121,6 +1139,41 @@ void JRenderer::RenderQuad(JQuad* quad, VertexColor* pt)
|
||||
|
||||
//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);
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
#else
|
||||
glRasterPos2f(pt[0].x, pt[0].y);
|
||||
|
||||
@@ -1195,7 +1248,33 @@ void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE
|
||||
glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] );
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
#else
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4ub(col.r, col.g, col.b, col.a);
|
||||
|
||||
@@ -1264,6 +1343,31 @@ void JRenderer::DrawRect(float x, float y, float width, float height, PIXEL_TYPE
|
||||
glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] );
|
||||
|
||||
glDrawArrays(GL_LINE_LOOP,0,4);
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4ub(col.r, col.g, col.b, col.a);
|
||||
@@ -1301,7 +1405,6 @@ void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE
|
||||
FillRect(x, y, width, height, col);
|
||||
}
|
||||
|
||||
|
||||
void JRenderer::FillRect(float x, float y, float width, float height, JColor* colors)
|
||||
{
|
||||
checkGlError();
|
||||
@@ -1339,6 +1442,30 @@ void JRenderer::FillRect(float x, float y, float width, float height, JColor* co
|
||||
glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] );
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glBegin(GL_QUADS);
|
||||
@@ -1404,6 +1531,28 @@ void JRenderer::DrawLine(float x1, float y1, float x2, float y2, PIXEL_TYPE colo
|
||||
glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] );
|
||||
|
||||
glDrawArrays(GL_LINES,0,2);
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4ub(col.r, col.g, col.b, col.a);
|
||||
@@ -1424,7 +1573,7 @@ void JRenderer::Plot(float x, float y, PIXEL_TYPE color)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
JColor col;
|
||||
col.color = color;
|
||||
#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
|
||||
#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);
|
||||
@@ -1444,7 +1593,7 @@ void JRenderer::PlotArray(float *x, float *y, int count, PIXEL_TYPE color)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
JColor col;
|
||||
col.color = color;
|
||||
#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
|
||||
#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<count;i++)
|
||||
@@ -1477,7 +1626,7 @@ static int getNextPower2(int width)
|
||||
}
|
||||
|
||||
|
||||
#if (!defined IOS)
|
||||
#if (!defined IOS) && (!defined QT_CONFIG)
|
||||
static void jpg_null(j_decompress_ptr cinfo __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
@@ -1665,8 +1814,10 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
||||
|
||||
if (strstr(filename, ".jpg")!=NULL || strstr(filename, ".JPG")!=NULL)
|
||||
LoadJPG(textureInfo, filename);
|
||||
#if (!defined IOS) && (!defined QT_CONFIG) && (!defined SDL_CONFIG)
|
||||
else if(strstr(filename, ".gif")!=NULL || strstr(filename, ".GIF")!=NULL)
|
||||
LoadGIF(textureInfo,filename);
|
||||
#endif
|
||||
else if(strstr(filename, ".png")!=NULL || strstr(filename, ".PNG")!=NULL)
|
||||
LoadPNG(textureInfo, filename);
|
||||
|
||||
@@ -1710,7 +1861,8 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
DWORD* line;
|
||||
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (!fileSystem->OpenFile(filename)) return JGE_ERR_CANT_OPEN_FILE;
|
||||
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)
|
||||
@@ -1781,8 +1933,8 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
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;
|
||||
@@ -1821,7 +1973,7 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
// }
|
||||
|
||||
|
||||
|
||||
#if (!defined IOS) && (!defined QT_CONFIG) && (!defined SDL_CONFIG)
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// GIF Support
|
||||
int JRenderer::image_readgif(void * handle, TextureInfo &textureInfo, DWORD * bgcolor, InputFunc readFunc, int mode __attribute__((unused)), int TextureFormat __attribute__((unused)))
|
||||
@@ -1983,6 +2135,7 @@ void JRenderer::LoadGIF(TextureInfo &textureInfo, const char *filename, int mode
|
||||
fileSys->CloseFile();
|
||||
return ;//*/
|
||||
}
|
||||
#endif //(!defined IOS) && (!defined QT_CONFIG) && (!defined SDL_CONFIG)
|
||||
|
||||
#elif (defined IOS)
|
||||
|
||||
@@ -2316,7 +2469,11 @@ void JRenderer::Enable2D()
|
||||
glMatrixMode (GL_PROJECTION); // Select The Projection Matrix
|
||||
glLoadIdentity (); // Reset The Projection Matrix
|
||||
|
||||
gluOrtho2D(0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f);
|
||||
#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);
|
||||
#else
|
||||
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
|
||||
@@ -2439,6 +2596,26 @@ void JRenderer::RenderTriangles(JTexture* texture, Vertex3D *vertices, int start
|
||||
glDrawArrays(GL_TRIANGLES,0,count*3);
|
||||
|
||||
delete[] colorCoords;
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
delete[] colorCoords;
|
||||
|
||||
#else
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (int i = 0; i < count; i++)
|
||||
@@ -2478,9 +2655,9 @@ void JRenderer::FillPolygon(float* x, float* y, int count, PIXEL_TYPE color)
|
||||
checkGlError();
|
||||
JColor col;
|
||||
col.color = color;
|
||||
int i;
|
||||
|
||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
||||
int i;
|
||||
GLubyte* colors = new GLubyte[count*4];
|
||||
GLfloat* vVertices = new GLfloat[count*3];
|
||||
|
||||
@@ -2520,12 +2697,44 @@ void JRenderer::FillPolygon(float* x, float* y, int count, PIXEL_TYPE color)
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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++)
|
||||
{
|
||||
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);
|
||||
|
||||
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_TRIANGLE_FAN);
|
||||
|
||||
for(int i=0; i<count;i++)
|
||||
for(i=0; i<count;i++)
|
||||
{
|
||||
glVertex2f(x[i],SCREEN_HEIGHT_F-y[i]);
|
||||
}
|
||||
@@ -2545,9 +2754,9 @@ void JRenderer::DrawPolygon(float* x, float* y, int count, PIXEL_TYPE color)
|
||||
checkGlError();
|
||||
JColor col;
|
||||
col.color = color;
|
||||
int i;
|
||||
|
||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
||||
int i;
|
||||
int number = count+1;
|
||||
GLfloat* vVertices = new GLfloat[3*number];
|
||||
GLubyte* colors = new GLubyte[4*number];
|
||||
@@ -2591,12 +2800,52 @@ void JRenderer::DrawPolygon(float* x, float* y, int count, PIXEL_TYPE color)
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
int number = count+1;
|
||||
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 < count;i++)
|
||||
{
|
||||
vVertices[3*i+0] = x[i];
|
||||
vVertices[3*i+1] = SCREEN_HEIGHT_F-y[i];
|
||||
vVertices[3*i+2] = 0.0f;
|
||||
}
|
||||
|
||||
vVertices[3*(number-1)+0] = x[0];
|
||||
vVertices[3*(number-1)+1] = SCREEN_HEIGHT_F-y[0];
|
||||
vVertices[3*(number-1)+2] = 0.0f;
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, vVertices);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors );
|
||||
glDrawArrays(GL_LINE_STRIP,0,number);
|
||||
|
||||
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_STRIP);
|
||||
|
||||
for(int i=0; i<count;i++)
|
||||
for(i=0; i<count;i++)
|
||||
{
|
||||
glVertex2f(x[i],SCREEN_HEIGHT_F-y[i]);
|
||||
}
|
||||
@@ -2691,6 +2940,44 @@ void JRenderer::DrawCircle(float x, float y, float radius, PIXEL_TYPE color)
|
||||
glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] );
|
||||
|
||||
glDrawArrays(GL_LINE_STRIP,0,number);
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
int i, index;
|
||||
const int number = 181;
|
||||
GLfloat vVertices[number][3];
|
||||
GLubyte colors[number][4];
|
||||
|
||||
for(i = 0; i < number; i++)
|
||||
{
|
||||
colors[i][0]= col.r;
|
||||
colors[i][1]= col.g;
|
||||
colors[i][2]= col.b;
|
||||
colors[i][3]= col.a;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
for(i=0; i < 360;i+=2, index++)
|
||||
{
|
||||
vVertices[index][0] = x+radius*COSF(i);
|
||||
vVertices[index][1] = SCREEN_HEIGHT_F-y+radius*SINF(i);
|
||||
vVertices[index][2] = 0.0f;
|
||||
}
|
||||
|
||||
vVertices[number-1][0] = x+radius*COSF(0);
|
||||
vVertices[number-1][1] = SCREEN_HEIGHT_F-y+radius*SINF(0);
|
||||
vVertices[number-1][2] = 0.0f;
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, vVertices);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors );
|
||||
glDrawArrays(GL_LINE_STRIP,0,number);
|
||||
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4ub(col.r, col.g, col.b, col.a);
|
||||
@@ -2765,6 +3052,48 @@ void JRenderer::FillCircle(float x, float y, float radius, PIXEL_TYPE color)
|
||||
glUniformMatrix4fv( prog1_mvpLoc, 1, GL_FALSE, (GLfloat*) &theMvpMatrix.m[0][0] );
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN,0,number);
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
int i, index;
|
||||
const int number = 182;
|
||||
GLfloat vVertices[number][3];
|
||||
GLubyte colors[number][4];
|
||||
|
||||
for(i = 0; i < number; i++)
|
||||
{
|
||||
colors[i][0]= col.r;
|
||||
colors[i][1]= col.g;
|
||||
colors[i][2]= col.b;
|
||||
colors[i][3]= col.a;
|
||||
}
|
||||
|
||||
vVertices[0][0] = x;
|
||||
vVertices[0][1] = SCREEN_HEIGHT_F-y;
|
||||
vVertices[0][2] = 0.0f;
|
||||
|
||||
index = 1;
|
||||
for(i=0; i < 360;i+=2, index++)
|
||||
{
|
||||
vVertices[index][0] = x+radius*COSF(i);
|
||||
vVertices[index][1] = SCREEN_HEIGHT_F-y+radius*SINF(i);
|
||||
vVertices[index][2] = 0.0f;
|
||||
}
|
||||
|
||||
vVertices[number-1][0] = x+radius*COSF(0);
|
||||
vVertices[number-1][1] = SCREEN_HEIGHT_F-y+radius*SINF(0);
|
||||
vVertices[number-1][2] = 0.0f;
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, vVertices);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors );
|
||||
glDrawArrays(GL_TRIANGLE_FAN,0,number);
|
||||
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4ub(col.r, col.g, col.b, col.a);
|
||||
@@ -2799,9 +3128,9 @@ void JRenderer::DrawPolygon(float x, float y, float size, int count, float start
|
||||
float angle = startingAngle*RAD2DEG;
|
||||
float steps = 360.0f/count;
|
||||
size /= 2;
|
||||
int i;
|
||||
|
||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
||||
int i;
|
||||
GLfloat* vVertices = new GLfloat[3*count];
|
||||
GLubyte* colors = new GLubyte[4*count];
|
||||
|
||||
@@ -2843,12 +3172,49 @@ void JRenderer::DrawPolygon(float x, float y, float size, int count, float start
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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<count;i++)
|
||||
{
|
||||
vVertices[3*i+0] = x+size*COSF((int)angle);
|
||||
vVertices[3*i+1] = SCREEN_HEIGHT_F-(y+size*SINF((int)angle));
|
||||
vVertices[3*i+2] = 0.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);
|
||||
|
||||
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(int i=0; i<count;i++)
|
||||
for(i=0; i<count;i++)
|
||||
{
|
||||
glVertex2f(x+size*COSF((int)angle), SCREEN_HEIGHT_F-(y+size*SINF((int)angle)));
|
||||
|
||||
@@ -2877,9 +3243,9 @@ void JRenderer::FillPolygon(float x, float y, float size, int count, float start
|
||||
float firstAngle = angle;
|
||||
float steps = 360.0f/count;
|
||||
size /= 2;
|
||||
int i;
|
||||
|
||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
||||
int i;
|
||||
GLfloat* vVertices = new GLfloat[3*(count+2)];
|
||||
GLubyte* colors = new GLubyte[4*(count+2)];
|
||||
|
||||
@@ -2929,6 +3295,51 @@ void JRenderer::FillPolygon(float x, float y, float size, int count, float start
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
vVertices[0] = x;
|
||||
vVertices[1] = SCREEN_HEIGHT_F-y;
|
||||
vVertices[2] = 0.0f;
|
||||
|
||||
for(i=1; i<count+1;i++)
|
||||
{
|
||||
vVertices[3*i+0] = x+size*COSF((int)angle);
|
||||
vVertices[3*i+1] = SCREEN_HEIGHT_F-y+size*SINF((int)angle);
|
||||
vVertices[3*i+2] = 0.0f;
|
||||
angle += steps;
|
||||
if (angle >= 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;
|
||||
|
||||
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);
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4ub(col.r, col.g, col.b, col.a);
|
||||
@@ -2936,7 +3347,7 @@ void JRenderer::FillPolygon(float x, float y, float size, int count, float start
|
||||
|
||||
glVertex2f(x, SCREEN_HEIGHT_F-y);
|
||||
|
||||
for(int i=0; i<count;i++)
|
||||
for(i=0; i<count;i++)
|
||||
{
|
||||
glVertex2f(x+size*COSF((int)angle), SCREEN_HEIGHT_F-y+size*SINF((int)angle));
|
||||
angle += steps;
|
||||
@@ -2971,9 +3382,9 @@ void JRenderer::DrawRoundRect(float x, float y, float w, float h, float radius,
|
||||
y+=h+radius;
|
||||
JColor col;
|
||||
col.color = color;
|
||||
int i;
|
||||
|
||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
|
||||
int i;
|
||||
int number = 360;
|
||||
GLfloat* vVertices = new GLfloat[3*number];
|
||||
GLubyte* colors = new GLubyte[4*number];
|
||||
@@ -3036,11 +3447,69 @@ void JRenderer::DrawRoundRect(float x, float y, float w, float h, float radius,
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
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<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=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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4ub(col.r, col.g, col.b, col.a);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
int i;
|
||||
|
||||
for(i=0; i<90;i++)
|
||||
{
|
||||
glVertex2f(x+radius*COSF(i), SCREEN_HEIGHT_F-(y+radius*SINF(i)));
|
||||
@@ -3165,6 +3634,70 @@ void JRenderer::FillRoundRect(float x, float y, float w, float h, float radius,
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#elif (defined GL_VERSION_ES_CM_1_1)
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
int i, offset;
|
||||
int number = 2+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;
|
||||
}
|
||||
|
||||
vVertices[0] = x-5; vVertices[1] = SCREEN_HEIGHT_F-y; vVertices[2] = 0.0f;
|
||||
offset = 1;
|
||||
for(i=0; i<90;i++) {
|
||||
vVertices[3*(offset+i)+0] = x+radius*COSF(i);
|
||||
vVertices[3*(offset+i)+1] = SCREEN_HEIGHT_F-y+radius*SINF(i);
|
||||
vVertices[3*(offset+i)+2] = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
for(i=90; i<180;i++)
|
||||
{
|
||||
vVertices[3*(offset+i)+0] = x+radius*COSF(i)-w;
|
||||
vVertices[3*(offset+i)+1] = SCREEN_HEIGHT_F-y+radius*SINF(i);
|
||||
vVertices[3*(offset+i)+2] = 0.0f;
|
||||
}
|
||||
|
||||
for(i=180; i<270;i++)
|
||||
{
|
||||
vVertices[3*(offset+i)+0] = x+radius*COSF(i)-w;
|
||||
vVertices[3*(offset+i)+1] = SCREEN_HEIGHT_F-y+radius*SINF(i)-h;
|
||||
vVertices[3*(offset+i)+2] = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
for(i=270; i<360;i++)
|
||||
{
|
||||
vVertices[3*(offset+i)+0] = x+radius*COSF(i);
|
||||
vVertices[3*(offset+i)+1] = SCREEN_HEIGHT_F-y+radius*SINF(i)-h;
|
||||
vVertices[3*(offset+i)+2] = 0.0f;
|
||||
}
|
||||
|
||||
vVertices[3*(361)+0] = x+radius*COSF(0);
|
||||
vVertices[3*(361)+1] = SCREEN_HEIGHT_F-y+radius*SINF(0);
|
||||
vVertices[3*(361)+2] = 0.0f;
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, vVertices);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors );
|
||||
glDrawArrays(GL_TRIANGLE_FAN,0,number);
|
||||
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
delete[] vVertices;
|
||||
delete[] colors;
|
||||
|
||||
#else
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user