Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -------------------------------------------------------------------------------------------
- S.D.L.(R) 1.2.x GTR Twin Turbo(OpenGL)
- Source (C)opyright 2010, by Silent Hero Productions(R)
- -------------------------------------------------------------------------------------------
- */
- #include "SDL/SDL.h"
- #include "SDL/SDL_image.h"
- #include "SDL/SDL_ttf.h"
- #include "SDL/SDL_opengl.h"
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- bool CoreFAILURE = false;
- SDL_Event Event;
- bool EXITgame = false;
- Uint32 SystemTicks = 0;
- Uint32 NextFrameTicks = 0;
- Uint32 NextSecondTick = 0;
- Uint32 NumberOfFramesPerSecond = 0;
- Uint32 FPSindex = 0;
- Uint32 FramesPerSecondArray[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- Uint32 AverageFPS = 0;
- struct PreLoadTexts
- {
- GLuint OGL_TextTexture;
- int TextWidth;
- int TextHeight;
- int TextureWidth;
- int TextureHeight;
- } PreLoadTextsArray[1];
- #define JustifyLeft 0
- #define JustifyCenter 1
- #define JustifyRight 2
- #define JustifyCenterOnPoint 3
- Uint32 rmask, gmask, bmask, amask;
- bool ColorIsRGBA = true;
- TTF_Font* Font = NULL;
- SDL_Color Color;
- char VariableText[64];
- int DrawText = 0;
- bool KeyUp = false;
- bool T_WasPressed = false;
- bool Q_IsPressed = false;
- bool W_IsPressed = false;
- bool A_IsPressed = false;
- bool S_IsPressed = false;
- #define NumberOfHappyFaces 200
- Sint32 randomX[NumberOfHappyFaces];
- Sint32 randomY[NumberOfHappyFaces];
- #define NumberOfTexts 100
- Sint32 randomTextX[NumberOfTexts];
- Sint32 randomTextY[NumberOfTexts];
- struct Sprite
- {
- GLuint OGL_Texture;
- int Width;
- int Height;
- int CenterX;
- int CenterY;
- GLfloat RotationDegree;
- } Sprites[2];
- SDL_Surface *Surface; // This surface will tell us the details of the image
- GLenum TextureFormat;
- GLint NumberOfColors;
- bool BMP_Dimensions_OK = true;
- bool BMP_To_Texture_OK = true;
- int X_Offset = 320;
- int Y_Offset = 240;
- //-------------------------------------------------------------------------------------------------
- int nextpoweroftwo(int x)
- {
- double logbase2 = log(x) / log(2);
- return round(pow(2,ceil(logbase2)));
- }
- //-------------------------------------------------------------------------------------------------
- void PreloadTestText()
- {
- SDL_Surface *initial;
- SDL_Surface *initialOutline;
- SDL_Surface *intermediary;
- SDL_Rect rect;
- int w,h;
- SDL_Color outline;
- SDL_Color color;
- PreLoadTextsArray[0].OGL_TextTexture = NULL;
- color.r = 255;
- color.g = 0;
- color.b = 0;
- outline.r = 1;
- outline.g = 1;
- outline.b = 1;
- // Use SDL_TTF to render our text
- initial = TTF_RenderText_Solid(Font, "Hello, World!", color);
- initialOutline = TTF_RenderText_Solid(Font, "Hello, World!", outline);
- PreLoadTextsArray[0].TextWidth = initial->w;
- PreLoadTextsArray[0].TextHeight = initial->h;
- // Convert the rendered text to a known format
- w = nextpoweroftwo(7+initial->w);
- h = nextpoweroftwo(7+initial->h);
- PreLoadTextsArray[0].TextureWidth = w;
- PreLoadTextsArray[0].TextureHeight = h;
- intermediary = SDL_CreateRGBSurface(0, w, h, 32, rmask, gmask, bmask, amask);
- rect.x = 3; rect.y = 0;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 0; rect.y = 3;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 6; rect.y = 3;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 3; rect.y = 6;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 3;
- rect.y = 3;
- SDL_BlitSurface(initial, 0, intermediary, &rect);
- // Tell GL about our new texture
- glGenTextures(1, &PreLoadTextsArray[0].OGL_TextTexture);
- glBindTexture(GL_TEXTURE_2D, PreLoadTextsArray[0].OGL_TextTexture);
- if (ColorIsRGBA == true)
- glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, intermediary->pixels );
- else
- glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_BGRA,
- GL_UNSIGNED_BYTE, intermediary->pixels );
- // Clean up
- SDL_FreeSurface(initial);
- SDL_FreeSurface(initialOutline);
- SDL_FreeSurface(intermediary);
- }
- //-------------------------------------------------------------------------------------------------
- void DrawPreloadedTestText(int XJustification, Sint32 posX, Sint32 posY)
- {
- if (XJustification == JustifyLeft)
- {
- }
- else if (XJustification == JustifyCenter)
- {
- posX = 320 - (PreLoadTextsArray[0].TextWidth / 2) - 2;
- }
- else if (XJustification == JustifyRight)
- {
- posX = (640 - posX) - PreLoadTextsArray[0].TextWidth - 2;
- }
- else if (XJustification == JustifyCenterOnPoint)
- {
- posX = posX - (PreLoadTextsArray[0].TextWidth / 2) - 2;
- }
- glBindTexture(GL_TEXTURE_2D, PreLoadTextsArray[0].OGL_TextTexture);
- // GL_NEAREST looks horrible, if scaled...
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // prepare to render our texture
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, PreLoadTextsArray[0].OGL_TextTexture);
- glColor3f(1.0f, 1.0f, 1.0f);
- // Draw a quad at location
- glBegin(GL_QUADS);
- // Recall that the origin is in the lower-left corner
- // That is why the TexCoords specify different corners
- // than the Vertex coors seem to.
- glTexCoord2f(0.0f, 1.0f);
- glVertex2f(posX , posY + PreLoadTextsArray[0].TextureHeight);
- glTexCoord2f(1.0f, 1.0f);
- glVertex2f(posX + PreLoadTextsArray[0].TextureWidth, posY + PreLoadTextsArray[0].TextureHeight);
- glTexCoord2f(1.0f, 0.0f);
- glVertex2f(posX + PreLoadTextsArray[0].TextureWidth, posY );
- glTexCoord2f(0.0f, 0.0f);
- glVertex2f(posX , posY );
- glEnd();
- }
- //-------------------------------------------------------------------------------------------------
- void SDL_GL_RenderText(const char *text, TTF_Font *font, SDL_Color color, int XJustification,
- Sint32 posX, Sint32 posY)
- {
- SDL_Surface *initial;
- SDL_Surface *initialOutline;
- SDL_Surface *intermediary;
- SDL_Rect rect;
- int w,h;
- GLuint textureThree;
- SDL_Color outline;
- if (XJustification == JustifyLeft)
- {
- }
- else if (XJustification == JustifyCenter)
- {
- posX = 320 - (PreLoadTextsArray[0].TextWidth / 2) - 2;
- }
- else if (XJustification == JustifyRight)
- {
- posX = (640 - posX) - PreLoadTextsArray[0].TextWidth - 2;
- }
- else if (XJustification == JustifyCenterOnPoint)
- {
- posX = posX - (PreLoadTextsArray[0].TextWidth / 2) - 2;
- }
- outline.r = 1;
- outline.g = 1;
- outline.b = 1;
- // Use SDL_TTF to render our text
- initial = TTF_RenderText_Solid(font, text, color);
- initialOutline = TTF_RenderText_Solid(font, text, outline);
- // Convert the rendered text to a known format
- w = nextpoweroftwo(7+initial->w);
- h = nextpoweroftwo(7+initial->h);
- intermediary = SDL_CreateRGBSurface(0, w, h, 32, rmask, gmask, bmask, amask);
- rect.x = 3; rect.y = 0;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 0; rect.y = 3;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 6; rect.y = 3;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 3; rect.y = 6;
- SDL_BlitSurface(initialOutline, 0, intermediary, &rect);
- rect.x = 3;
- rect.y = 3;
- SDL_BlitSurface(initial, 0, intermediary, &rect);
- // Tell GL about our new texture
- glGenTextures(1, &textureThree);
- glBindTexture(GL_TEXTURE_2D, textureThree);
- if (ColorIsRGBA == true)
- glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, intermediary->pixels );
- else
- glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_BGRA,
- GL_UNSIGNED_BYTE, intermediary->pixels );
- // GL_NEAREST looks horrible, if scaled...
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // prepare to render our texture
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, textureThree);
- glColor3f(1.0f, 1.0f, 1.0f);
- // Draw a quad at location
- glBegin(GL_QUADS);
- // Recall that the origin is in the lower-left corner
- // That is why the TexCoords specify different corners
- // than the Vertex coors seem to.
- glTexCoord2f(0.0f, 1.0f);
- glVertex2f(posX , posY + h);
- glTexCoord2f(1.0f, 1.0f);
- glVertex2f(posX + w, posY + h);
- glTexCoord2f(1.0f, 0.0f);
- glVertex2f(posX + w, posY );
- glTexCoord2f(0.0f, 0.0f);
- glVertex2f(posX , posY );
- glEnd();
- // Bad things happen if we delete the texture before it finishes
- glFinish();
- // return the deltas in the unused w,h part of the rect
- /// location->w = initial->w;
- /// location->h = initial->h;
- // Clean up
- SDL_FreeSurface(initial);
- SDL_FreeSurface(initialOutline);
- SDL_FreeSurface(intermediary);
- glDeleteTextures(1, &textureThree);
- }
- //-------------------------------------------------------------------------------------------------
- void CalculateRandomPositions(void)
- {
- for (int index = 0; index < NumberOfHappyFaces; index++)
- {
- randomX[index] = rand()%1040;
- randomX[index]-=200;
- randomY[index] = rand()%880;
- randomY[index]-=200;
- }
- for (int index = 0; index < NumberOfTexts; index++)
- {
- randomTextX[index] = rand()%1040;
- randomTextX[index]-=200;
- randomTextY[index] = rand()%880;
- randomTextY[index]-=200;
- }
- }
- //-------------------------------------------------------------------------------------------------
- void MoveRandomPositions(void)
- {
- for (int index = 0; index < NumberOfHappyFaces; index++)
- {
- randomY[index]-=1;
- if (randomY[index] < -200) randomY[index] = 680;
- }
- }
- //-------------------------------------------------------------------------------------------------
- void DrawTestTextures(void)
- {
- if (BMP_To_Texture_OK == true)
- {
- for (int index = 0; index < NumberOfHappyFaces; index++)
- {
- // Bind the texture to which subsequent calls refer to
- glBindTexture( GL_TEXTURE_2D, Sprites[0].OGL_Texture );
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glBegin( GL_QUADS ); // Draw textures
- //Top-left vertex (corner)
- glTexCoord2i( 0, 0 );
- glVertex3f( randomX[index]+Sprites[0].CenterX, randomY[index]+Sprites[0].CenterY, 0.0f );
- //Bottom-left vertex (corner)
- glTexCoord2i( 1, 0 );
- glVertex3f( randomX[index]+Sprites[0].CenterX+Sprites[0].Width, randomY[index]+Sprites[0].CenterY, 0 );
- //Bottom-right vertex (corner)
- glTexCoord2i( 1, 1 );
- glVertex3f( randomX[index]+Sprites[0].CenterX+Sprites[0].Width, randomY[index]+Sprites[0].CenterY+Sprites[0].Height, 0 );
- //Top-right vertex (corner)
- glTexCoord2i( 0, 1 );
- glVertex3f( randomX[index]+Sprites[0].CenterX, randomY[index]+Sprites[0].CenterY+Sprites[0].Height, 0 );
- glEnd();
- }
- }
- }
- //-------------------------------------------------------------------------------------------------
- void DrawMovableScalableTestTexture(void)
- {
- if (BMP_To_Texture_OK == true)
- {
- // Bind the texture to which subsequent calls refer to
- glBindTexture( GL_TEXTURE_2D, Sprites[1].OGL_Texture );
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glBegin( GL_QUADS ); // Draw texture with scaling
- //Top-left vertex (corner)
- glTexCoord2i( 0, 0 );
- glVertex3f( X_Offset-Sprites[1].CenterX, Y_Offset-Sprites[1].CenterY, 0.0f );
- //Bottom-left vertex (corner)
- glTexCoord2i( 1, 0 );
- glVertex3f( X_Offset-Sprites[1].CenterX+Sprites[1].Width, Y_Offset-Sprites[1].CenterY, 0 );
- //Bottom-right vertex (corner)
- glTexCoord2i( 1, 1 );
- glVertex3f( X_Offset-Sprites[1].CenterX+Sprites[1].Width, Y_Offset-Sprites[1].CenterY+Sprites[1].Height, 0 );
- //Top-right vertex (corner)
- glTexCoord2i( 0, 1 );
- glVertex3f( X_Offset-Sprites[1].CenterX, Y_Offset-Sprites[1].CenterY+Sprites[1].Height, 0 );
- glEnd();
- glEnd();
- }
- }
- //-------------------------------------------------------------------------------------------------
- int main( int argc, char* args[] )
- {
- if ( SDL_Init(SDL_INIT_EVERYTHING) != 0 )
- {
- printf("ERROR: Unable to initialize SDL: %s\n", SDL_GetError());
- CoreFAILURE = true;
- }
- else printf("SDL (Everything) initialized\n");
- if ( TTF_Init() == -1 )
- {
- fprintf(stderr, "ERROR: TTF_Init: %s\n", TTF_GetError());
- CoreFAILURE = true;
- }
- else fprintf(stdout, "SDL_TTF initialized\n");
- Font = NULL;
- if( !(Font = TTF_OpenFont("data/fonts/default.ttf", 26)) )
- {
- printf("ERROR: loading font: %s\n", TTF_GetError());
- CoreFAILURE = true;
- }
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
- putenv(strdup("SDL_VIDEO_CENTERED=1"));
- SDL_WM_SetCaption("SDL+OpenGL(GTR Twin Turbo)", NULL);
- SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 0, SDL_OPENGL);
- if (!screen)
- {
- printf("ERROR: SDL 640x480 window init failed\n");
- CoreFAILURE = true;
- }
- glEnable( GL_TEXTURE_2D );
- glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
- glViewport( 0, 0, 640, 480 );
- glClear( GL_COLOR_BUFFER_BIT );
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f);
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- printf("OpenGL initialized\n");
- Surface = NULL;
- if ( (Surface = IMG_Load("data/graphics/image.png")) )
- {
- // Check that the image's width is a power of 2
- if ( (Surface->w & (Surface->w - 1)) != 0 )
- {
- printf("ERROR: image.bmp's width is not a power of 2\n");
- BMP_Dimensions_OK = false;
- CoreFAILURE = true;
- }
- // Also check if the height is a power of 2
- if ( (Surface->h & (Surface->h - 1)) != 0 )
- {
- printf("ERROR: image.bmp's height is not a power of 2\n");
- BMP_Dimensions_OK = false;
- CoreFAILURE = true;
- }
- Sprites[0].Width = Surface->w;
- Sprites[0].Height = Surface->h;
- Sprites[0].CenterX = Sprites[0].Width / 2;
- Sprites[0].CenterY = Sprites[0].Height / 2;
- Sprites[0].RotationDegree = 0;
- Sprites[1].Width = Surface->w;
- Sprites[1].Height = Surface->h;
- Sprites[1].CenterX = Sprites[1].Width / 2;
- Sprites[1].CenterY = Sprites[1].Height / 2;
- Sprites[1].RotationDegree = 0;
- if (BMP_Dimensions_OK == true)
- {
- // get the number of channels in the SDL surface
- NumberOfColors = Surface->format->BytesPerPixel;
- if (NumberOfColors == 4) // contains an alpha channel
- {
- //if (Surface->format->Rmask == 0x000000ff)
- TextureFormat = GL_RGBA;
- //else
- // TextureFormat = GL_BGRA;
- }
- else if (NumberOfColors == 3) // no alpha channel
- {
- //if (Surface->format->Rmask == 0x000000ff)
- TextureFormat = GL_RGB;
- //else
- // TextureFormat = GL_BGR;
- }
- else
- {
- printf("ERROR: the image is not truecolor\n");
- BMP_To_Texture_OK = false;
- CoreFAILURE = true;
- }
- if (BMP_To_Texture_OK == true)
- {
- // Have OpenGL generate a texture object handle for us
- glGenTextures( 1, &Sprites[0].OGL_Texture );
- // Bind the texture object
- glBindTexture( GL_TEXTURE_2D, Sprites[0].OGL_Texture );
- // Set the texture's stretching properties
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- // Edit the texture object's image data using the information SDL_Surface gives us
- glTexImage2D( GL_TEXTURE_2D, 0, NumberOfColors, Surface->w, Surface->h, 0,
- TextureFormat, GL_UNSIGNED_BYTE, Surface->pixels );
- // Have OpenGL generate a texture object handle for us
- glGenTextures( 1, &Sprites[1].OGL_Texture );
- // Bind the texture object
- glBindTexture( GL_TEXTURE_2D, Sprites[1].OGL_Texture );
- // Set the texture's stretching properties
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- // Edit the texture object's image data using the information SDL_Surface gives us
- glTexImage2D( GL_TEXTURE_2D, 0, NumberOfColors, Surface->w, Surface->h, 0,
- TextureFormat, GL_UNSIGNED_BYTE, Surface->pixels );
- // Free the SDL_Surface only if it was successfully created
- if ( Surface )
- {
- SDL_FreeSurface( Surface );
- }
- }
- }
- }
- else
- {
- printf("ERROR: SDL could not load image.png: %s\n", SDL_GetError());
- BMP_To_Texture_OK = false;
- }
- /* SDL interprets each pixel as a 32-bit number, so our masks must depend
- on the endianness (byte order) of the machine */
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
- ColorIsRGBA = true;
- #else
- rmask = 0x00ff0000;
- gmask = 0x0000ff00;
- bmask = 0x000000ff;
- amask = 0xff000000;
- ColorIsRGBA = false;
- #endif
- srand( (unsigned)time( NULL ) );
- CalculateRandomPositions();
- SystemTicks = SDL_GetTicks();
- NextSecondTick = SystemTicks+1000;
- NumberOfFramesPerSecond = 0;
- AverageFPS = 0;
- PreloadTestText();
- printf("Main Loop executed!\n");
- //-------------------------------------------------------------------------------
- // MAIN LOOP
- while (CoreFAILURE != true && EXITgame == false)
- {
- SystemTicks = SDL_GetTicks();
- NextFrameTicks = SystemTicks + 17; // About 60 Frames Per Second!
- NumberOfFramesPerSecond++;
- if (SystemTicks > NextSecondTick)
- {
- FPSindex++;
- if (FPSindex > 9)
- {
- FPSindex = 0;
- }
- FramesPerSecondArray[FPSindex] = NumberOfFramesPerSecond;
- AverageFPS = 0;
- for (int index = 0; index < 10; index++)
- {
- AverageFPS += FramesPerSecondArray[index];
- }
- AverageFPS = AverageFPS / 10;
- NumberOfFramesPerSecond = 0;
- NextSecondTick = SystemTicks+1000;
- }
- while( SDL_PollEvent( &Event ) )
- {
- }
- KeyUp = false;
- switch( Event.type )
- {
- case SDL_QUIT:
- EXITgame = true;
- break;
- case SDL_KEYUP:
- switch ( Event.key.keysym.sym )
- {
- case SDLK_t:
- T_WasPressed = false;
- KeyUp = true;
- break;
- case SDLK_q:
- Q_IsPressed = false;
- W_IsPressed = false;
- KeyUp = true;
- break;
- case SDLK_w:
- W_IsPressed = false;
- Q_IsPressed = false;
- KeyUp = true;
- break;
- case SDLK_a:
- A_IsPressed = false;
- S_IsPressed = false;
- KeyUp = true;
- break;
- case SDLK_s:
- S_IsPressed = false;
- A_IsPressed = false;
- KeyUp = true;
- break;
- default:
- break;
- }
- case SDL_KEYDOWN:
- switch( Event.key.keysym.sym )
- {
- case SDLK_ESCAPE:
- EXITgame = true;
- break;
- case SDLK_t:
- if (KeyUp == false && T_WasPressed == false)
- {
- if (DrawText == 0) DrawText = 1;
- else if (DrawText == 1) DrawText = 2;
- else if (DrawText == 2) DrawText = 3;
- else if (DrawText == 3) DrawText = 0;
- T_WasPressed = true;
- }
- break;
- case SDLK_q:
- if (KeyUp == false)
- {
- Q_IsPressed = true;
- }
- break;
- case SDLK_w:
- if (KeyUp == false)
- {
- W_IsPressed = true;
- }
- break;
- break;
- case SDLK_a:
- if (KeyUp == false)
- {
- A_IsPressed = true;
- }
- break;
- case SDLK_s:
- if (KeyUp == false)
- {
- S_IsPressed = true;
- }
- break;
- default:
- break;
- }
- }
- if (Q_IsPressed == true)
- {
- if (Sprites[1].Width > 0) Sprites[1].Width--;
- Sprites[1].CenterX = Sprites[1].Width / 2;
- if (Sprites[1].Height > 0) Sprites[1].Height--;
- Sprites[1].CenterY = Sprites[1].Height / 2;
- }
- else if (W_IsPressed == true)
- {
- if (Sprites[1].Width < 1000) Sprites[1].Width++;
- Sprites[1].CenterX = Sprites[1].Width / 2;
- if (Sprites[1].Height < 1000) Sprites[1].Height++;
- Sprites[1].CenterY = Sprites[1].Height / 2;
- }
- if (A_IsPressed == true)
- {
- if (Sprites[1].RotationDegree > 0) Sprites[1].RotationDegree--;
- else Sprites[1].RotationDegree = 359;
- }
- else if (S_IsPressed == true)
- {
- if (Sprites[1].RotationDegree < 359) Sprites[1].RotationDegree++;
- else Sprites[1].RotationDegree = 0;
- }
- Uint8 *keystates = SDL_GetKeyState( NULL );
- if ( keystates[ SDLK_UP ] && Y_Offset > -300) Y_Offset--;
- else if ( keystates[ SDLK_DOWN ] && Y_Offset < 780) Y_Offset++;
- else if ( keystates[ SDLK_LEFT ] && X_Offset > -300) X_Offset--;
- else if ( keystates[ SDLK_RIGHT ] && X_Offset < 940) X_Offset++;
- glClearColor( 0.0f, 1.0f, 0.0f, 0.0f ); // Green OGL clear color
- glClear( GL_COLOR_BUFFER_BIT );
- MoveRandomPositions();
- DrawTestTextures();
- Color.r = 255;
- Color.g = 0;
- Color.b = 0;
- /// A quick note about position.
- /// * Enable2D puts the origin in the lower-left corner of the
- /// * screen, which is different from the normal coordinate
- /// * space of most 2D api's. position, therefore,
- /// * gives the X,Y coordinates of the lower-left corner of the
- /// * rectangle
- for (int index = 0; index < NumberOfTexts; index++)
- {
- if (DrawText < 1 || DrawText == 3) DrawPreloadedTestText(JustifyLeft, randomTextX[index], randomTextY[index]);
- }
- DrawMovableScalableTestTexture();
- char temp[256];
- strcpy(VariableText, "F.P.S.:");
- sprintf(temp, "%d", AverageFPS);
- strcat(VariableText, temp);
- strcat(VariableText," ~60");
- Color.r = 0;
- Color.g = 0;
- Color.b = 255;
- if (DrawText < 2) SDL_GL_RenderText(VariableText, Font, Color, JustifyCenter, 5, 5);
- SDL_GL_SwapBuffers();
- SystemTicks = SDL_GetTicks();
- if (NextFrameTicks > SystemTicks) SDL_Delay(NextFrameTicks-SystemTicks);
- }
- // MAIN LOOP
- //-------------------------------------------------------------------------------
- if (PreLoadTextsArray[0].OGL_TextTexture) glDeleteTextures( 1, &PreLoadTextsArray[0].OGL_TextTexture );
- if (PreLoadTextsArray[1].OGL_TextTexture) glDeleteTextures( 1, &PreLoadTextsArray[1].OGL_TextTexture );
- if (BMP_To_Texture_OK == true) glDeleteTextures( 1, &Sprites[0].OGL_Texture );
- if (Font != NULL) TTF_CloseFont(Font);
- TTF_Quit();
- SDL_Quit();
- printf("SDL+OGL application successfully closed\n");
- return 0;
- }
- // TM
- // "A 100% By JeZ+Lee" of Silent Hero Productions(R)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement