Sign in to follow this  
chris carey

Starting menu,backround. Cursor for rpg game

Recommended Posts

Cant seem to get it to display my images at all and also, how would i get a cursor to select either start or load then get it to change screens and load the intro (rpg game)
thanks chris


// specific headers
#include "SDL.h"
#include "SDL_opengl.h"
#include "SDL_image.h"
#include <iostream>
#include <string>

//Function for loading an image into an texture
GLuint loadTexture( const std::string &fileName )
{
SDL_Surface *image = IMG_Load( fileName.c_str() );

SDL_DisplayFormatAlpha(image);

unsigned object(0);

glGenTextures(1, &object);

glBindTexture(GL_TEXTURE_2D, object);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);

//Free surface
SDL_FreeSurface(image);

return object;
}

//start of the program
int main( int argc, char* args[] )
{
//initialize SDL
SDL_Init(SDL_INIT_EVERYTHING);

//Set OpenGL memory usage
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_BUFFER_SIZE, 32);
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

//Caption of the window
SDL_WM_SetCaption( "Our first game", NULL );

//Size of the window
SDL_SetVideoMode(600,400,32, SDL_OPENGL );

//Specific the clear color
glClearColor(1,1,1,1); //RED,GREEN,BLUE,ALPHA

//What portion of the screen we will display
glViewport(0,0,600,400);

//Shader model - Use this
glShadeModel(GL_SMOOTH);

//2D rendering
glMatrixMode(GL_PROJECTION);

//"Save" it
glLoadIdentity();

//Disable depth checking
glDisable(GL_DEPTH_TEST);

//We enable blending of textures and set how we are going to blend it
glEnable( GL_BLEND );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


std::cout << "OpenGL is running\n";
std::cout << "Main loop has started\n";

//Handles the main loop
bool isRunning = true;

//For handling with event
SDL_Event event;


bool left = false,right = false,up = false,down = false,p = false, l = false,o = false,k = false



//Create an texture
unsigned int backround = 0;
backround = loadTexture("backround.png");



//Main game loop
while ( isRunning )
{
//EVENTS
while ( SDL_PollEvent(&event) )
{
//if the window was closed
if ( event.type == SDL_QUIT )
{
isRunning = false;
}
if ( event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE )
{
isRunning = false;
}

if ( event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_r )
{
glClearColor(1,0,0,1);
}
if ( event.type == SDL_KEYDOWN ) //Check for presed down buttons
{
if ( event.key.keysym.sym == SDLK_LEFT ) //Left key
{
left = true; //Set the value to false (key is released)
}

if ( event.key.keysym.sym == SDLK_RIGHT ) //Right key
{
right = true; //Key is released
}
if ( event.key.keysym.sym == SDLK_UP )
{
up = true;
}
if (event.key.keysym.sym == SDLK_DOWN )
{
down = true;
}
if ( event.key.keysym.sym == SDLK_p ) //Left key
{
p = true; //Set the value to false (key is released)
}

if ( event.key.keysym.sym == SDLK_l ) //Right key
{
l = true; //Key is released
}
if ( event.key.keysym.sym == SDLK_o )
{
o = true;
}
else if (event.key.keysym.sym == SDLK_k )
{
k = true;
}

}

else if ( event.type == SDL_KEYUP ) //Checking for released buttons
{
if ( event.key.keysym.sym == SDLK_LEFT ) //Left key
{
left = false; //Set the value to false (key is released)
}

if ( event.key.keysym.sym == SDLK_RIGHT ) //Right key
{
right = false; //Key is released
}
if ( event.key.keysym.sym == SDLK_UP )
{
up = false;
}
else if (event.key.keysym.sym == SDLK_DOWN )
{
down = false;
}
if ( event.key.keysym.sym == SDLK_p ) //Left key
{
p = false; //Set the value to false (key is released)
}

if ( event.key.keysym.sym == SDLK_l ) //Right key
{
l = false; //Key is released
}
if ( event.key.keysym.sym == SDLK_o )
{
o = false;
}
else if (event.key.keysym.sym == SDLK_k )
{
k = false;
}
}

//LOGIC

//RENDERING to the screen

glClear(GL_COLOR_BUFFER_BIT);

glPushMatrix(); //Start rendering phase

glOrtho(0,600,400,0,-1,1); //Set the matrix

glColor4ub(255,255,255,255); //White color

//Enable textures when we are going to blend an texture
glEnable(GL_TEXTURE_2D);
//What texture we are going to use
glBindTexture(GL_TEXTURE_2D,backround);

glBegin(GL_QUADS); //Start drawing the backround item

//We set the corners of the texture using glTexCoord2d
glTexCoord2d(0,0); glVertex2f(0,0); //Upper-left corner
glTexCoord2d(1,0); glVertex2f(600,0); //Upper-right corner
glTexCoord2d(1,1); glVertex2f(600,400); //Down-right corner
glTexCoord2d(0,1); glVertex2f(0,400); //Down-left corner

glEnd(); //End drawing

//Disable textures when we are done using them
glDisable(GL_TEXTURE_2D);




}




glEnd();

glPopMatrix(); //End rendering phase

SDL_GL_SwapBuffers();

SDL_Delay(1); //Delay / pause
}

SDL_Quit();

return 0;
} Edited by chris carey

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this