Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #ifdef _WIN32
- #include <windows.h>
- #endif
- #ifdef __APPLE__
- #include <SDL.h>
- #include <SDL_mixer.h>
- #include <SDL_image.h>
- #include <SDL_ttf.h>
- #include <SDL_opengl.h>
- #include <OpenGL/gl.h>
- #include <OpenGL/glu.h>
- #else
- // #if SDL_VERSION_ATLEAST(2,0,0)
- /* SDL 2.0 code */
- #include <SDL.h>
- #include <SDL_mixer.h>
- #include <SDL_image.h>
- #include <SDL_ttf.h>
- //#include <SDL_opengl.h>
- /* #else
- /* SDL 1.2 code
- #include <SDL/SDL.h>
- #include <SDL/SDL_mixer.h>
- #include <SDL/SDL_image.h>
- #include <SDL/SDL_ttf.h>
- #include <SDL/SDL_opengl.h>
- #endif
- */
- #include <GLES/gl.h>
- //#include <GL/glu.h>
- #endif
- #ifdef __APPLE__
- #include "CoreFoundation/CoreFoundation.h"
- #endif
- #include <math.h>
- #include <time.h>
- #include "../../common/include/gui.h"
- #include <jni.h>
- // g_env is set in SDL_android_main.cpp
- extern JNIEnv *g_env;
- //#define LOSEPOWER
- #define MAXTEX 128
- #define MAXWH 256
- #define TURRETMAX MAXTEX
- #define WIDTH 800
- #define HEIGHT 480
- #define BPP 32
- #define EN(x) printf("Entering %s\n",x);
- #define EX(x) printf("Exiting %s\n",x);
- #define MAXARRAY 256
- #define EMAX 128
- #define BOSSAT 9
- #define PI 3.14159265
- const int FRAMES_PER_SECOND = 100;
- #include <android/log.h>
- #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "org.libsdl.app",__VA_ARGS__)
- #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , "org.libsdl.app",__VA_ARGS__)
- #define LOGI(...) __android_log_print(ANDROID_LOG_INFO , "org.libsdl.app",__VA_ARGS__)
- #define LOGW(...) __android_log_print(ANDROID_LOG_WARN , "org.libsdl.app",__VA_ARGS__)
- #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR , "org.libsdl.app",__VA_ARGS__)
- int main(int argc, char *argv[])
- {
- // PROGRAM VARABLES : REQUIRED VARABLES
- SDL_Event event;
- SDL_Keysym keysym;
- int quit=0;
- GLubyte *vendor;
- GLubyte *renderer;
- GLubyte *version;
- GLubyte *extensions;
- // PROGRAM VARABLES
- struct container screen;
- int len=0;
- int key=0;
- int d,e,l,f;
- struct textures menuList[MAXTEX];
- GLuint menuCount=0;
- GLuint menuTextures[MAXTEX];
- int menuW[MAXTEX]; int menuW2[MAXTEX];
- int menuH[MAXTEX]; int menuH2[MAXTEX];
- GLfloat texcoord[4];
- char text[100];
- // Set screen resolution
- screen.area.x=0;
- screen.area.y=0;
- screen.area.w=WIDTH;
- screen.area.h=HEIGHT;
- int windowed=0;
- int err=0;
- // Run OGL/SDL Startup code
- startup(&screen,&windowed,vendor,renderer,version,extensions);
- LOGD("SDL Started OK");
- // You should check the return value, here we assume logo.png is found
- // Do whatever you want with the rwops
- SDL_Surface *i = IMG_Load("cover.png");
- menuCount=1;
- SDL_GL_LoadTexture(i,menuTextures,&menuCount, texcoord,menuW,menuH,menuW2, menuH2);
- LOGD("Texture Loaded OK");
- // Draw Title While loading
- SDL_GL_Enter2DMode();
- err=glGetError();
- sprintf(text,"GL ERROR CODE 1 IN MAIN IS %d",err);
- LOGD(text);
- // Draw Loading Progress
- GLint texSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
- sprintf(text,"Dimensions: %d %d %d %d Max Texture Size: %d",menuW[0],menuH[0],menuW2[0],menuH2[0],texSize);
- LOGD(text);
- // Main Loop
- while ( ! quit )
- {
- // Event Handling
- while ( SDL_PollEvent( &event ) )
- {
- switch(event.type)
- {
- case SDL_FINGERDOWN:
- quit=1;
- break;
- case SDL_QUIT:
- quit=1;
- break;
- }
- }
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- draw(&screen,0,menuTextures,0,0,menuW[0],menuH[0],menuW2[0],menuH2[0]);
- SDL_GL_SwapWindow(screen.image);
- }
- LOGD("Program Closing, Cleaning up");
- glDeleteTextures(menuCount,menuTextures);
- SDL_Quit();
- exit(0);
- return(0);
- }
- int SDL_GL_LoadTexture(SDL_Surface *tempSurf, GLuint *texture, GLuint *texcount, GLfloat *texcoord, int *w, int *h, int *w2, int *h2)
- {
- //SDL_Surface *tempSurf[100];
- SDL_Surface *surface[100];
- int d=0;
- int x,y;
- int tempW[100];
- int tempH[100];
- int err=0;
- char text[100];
- SDL_Rect area;
- Uint32 saved_flags;
- Uint8 saved_alpha;
- // Load all surfaces in list
- //for(d=0;d<*(texcount);d++)
- //{
- //tempSurf=loadSurface(list[d].name);
- *(w)=0;
- *(h)=0;
- *(w) = tempSurf->w;
- *(h) = tempSurf->h;
- tempW[0]=0;
- tempH[0]=0;
- tempW[0]=pow2(*(w+d));
- tempH[0]=pow2(*(h+d));
- *(w2)=0;
- *(h2)=0;
- *(w2)=tempW[0];
- *(h2)=tempH[0];
- for(d=0;d<*(texcount);d++)
- {
- if ( tempSurf->format->BytesPerPixel == 3 )
- {
- surface[d] = SDL_CreateRGBSurface(
- SDL_SWSURFACE,
- tempW[d], tempH[d],
- 24,
- #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
- 0x000000FF,
- 0x0000FF00,
- 0x00FF0000,
- 0xFF000000
- #else
- 0xFF000000,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF
- #endif
- );
- }else{
- surface[d] = SDL_CreateRGBSurface(
- SDL_SWSURFACE,
- tempW[d], tempH[d],
- 32,
- #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
- 0x000000FF,
- 0x0000FF00,
- 0x00FF0000,
- 0xFF000000
- #else
- 0xFF000000,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF
- #endif
- );
- }
- /*
- // Save the alpha blending attributes
- saved_flags = tempSurf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
- saved_alpha = tempSurf->format->alpha;
- if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
- {
- SDL_SetAlpha(tempSurf, 0, 0);
- }*/
- SDL_SetSurfaceBlendMode(tempSurf, SDL_BLENDMODE_NONE);
- SDL_GetSurfaceAlphaMod(tempSurf,&saved_alpha);
- SDL_SetSurfaceAlphaMod(tempSurf,255);
- SDL_BlitSurface(tempSurf, NULL, surface[0], NULL);
- SDL_SetSurfaceAlphaMod(tempSurf,saved_alpha);
- /*
- // Restore the alpha blending attributes
- if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
- {
- SDL_SetAlpha(tempSurf, saved_flags, saved_alpha);
- }*/
- }
- // Genorate and bind textures in list
- glGenTextures(*(texcount), texture);
- for(d=0;d<*(texcount);d++)
- {
- glBindTexture(GL_TEXTURE_2D, *(texture+d));
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- if ( surface[d]->format->BytesPerPixel == 3 )
- {
- glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,tempW[d],tempH[d],0,GL_RGB,GL_UNSIGNED_BYTE,surface[d]->pixels);
- }else{
- glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,tempW[d],tempH[d],0,GL_RGBA,GL_UNSIGNED_BYTE,surface[d]->pixels);
- }
- }
- err=glGetError();
- sprintf(text,"GL ERROR CODE IS %d",err);
- LOGD(text);
- if ( surface[0]->pixels != NULL )
- {
- LOGD("Image has data");
- }
- SDL_FreeSurface(tempSurf);
- for(d=0;d<*(texcount);d++)
- {
- SDL_FreeSurface(surface[d]);
- }
- return(0);
- }
- int draw(struct container *screen, int entity, GLuint *texture, int x, int y, int w, int h, int tempW, int tempH)
- {
- // open png for tile
- //SDL_GL_Enter2DMode();
- //int tempW=pow2(w);
- //int tempH=pow2(h);
- float height=(float)h/(float)tempH;
- float width=(float)w/(float)tempW;
- glBindTexture( GL_TEXTURE_2D, *(texture+entity) );
- const GLfloat t[8] = { 0.0, 0.0, width, 0.0, width, height, 0.0, height };
- const GLshort v[8] = { x, y, x+w, y, x+w, y+h, x, y+h };
- glVertexPointer( 2, GL_SHORT, 0, v );
- glEnableClientState( GL_VERTEX_ARRAY );
- glTexCoordPointer( 2, GL_FLOAT, 0, t );
- glEnableClientState( GL_TEXTURE_COORD_ARRAY );
- glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
- return(0);
- }
- void SDL_GL_Enter2DMode()
- {
- glColor4ub(255,255,255,255);
- glEnable(GL_TEXTURE_2D);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//GL_DECAL);
- //glPushAttrib(GL_ENABLE_BIT);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
- glDisable( GL_LIGHTING );
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement