Hello,
I'm trying to port my program to windows (I program mainly on mac/linux) and I just can't make it work.
I'm using SDL for event management and OpenGL for drawing.
The code compiles without any problems but when I launch the program on windows a window with a white background appears and crashes after 2 seconds.
I've noticed that if I remove the "SDL_OPENGL" argument when initialising the window the program won't crash and SDL will work fine (take keyboard input, play music etc.).
I am using Orwell's DevCpp and I am linking to opengl32.lib, sdl.lib, sdlmain.lib, sdl_ttf.lib, sdl_mixer.lib, sdl_image.lib.
Here's my code:
Main.cpp
Rooms.h
Init.h
I apologize if you might find the code hard to read, I have some problems with commenting but I am trying to get better at it![:)]()
Thanks for any help
I'm trying to port my program to windows (I program mainly on mac/linux) and I just can't make it work.
I'm using SDL for event management and OpenGL for drawing.
The code compiles without any problems but when I launch the program on windows a window with a white background appears and crashes after 2 seconds.
I've noticed that if I remove the "SDL_OPENGL" argument when initialising the window the program won't crash and SDL will work fine (take keyboard input, play music etc.).
I am using Orwell's DevCpp and I am linking to opengl32.lib, sdl.lib, sdlmain.lib, sdl_ttf.lib, sdl_mixer.lib, sdl_image.lib.
Here's my code:
Main.cpp
#include "Rooms.h"
int main(int argc,char** argv){
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen=SDL_SetVideoMode(1024, 740, 32, SDL_SWSURFACE|SDL_OPENGL);
Uint32 start;
SDL_Event event;
init();
//SDL_WM_GrabInput( SDL_GRAB_ON );
SDL_ShowCursor(SDL_DISABLE);
menu();
//While the user hasn't quit
while( quit == false )
{
start=SDL_GetTicks();
//If there is no music playing
if( Mix_PlayingMusic() == 0 )
{
//Play the music
if( Mix_PlayMusic( music, 0 ) == -1 )
{
return 1;
}
Mix_VolumeMusic(music_v);
}
//While there's events to handle
while( SDL_PollEvent( &event ) && quit==false ){
if (event.type == SDL_MOUSEMOTION){
SDL_GetMouseState(&m_x, &m_y);
if (m_flashl==true){
if (m_y>=595){
m_y=590; SDL_WarpMouse(m_x, m_y);}
draw();
loop++;}
}
//If the user hasn't entered their name yet
if( nameEntered == false ){
//"HANDLE INPUT!!!"
if( event.type == SDL_KEYDOWN ){
string temp = str;
//If the key is a space
if( event.key.keysym.unicode == (Uint16)' ' )
{
//Append the character
str += (char)event.key.keysym.unicode;
}
//If the key is a number
else if( ( event.key.keysym.unicode >= (Uint16)'0' ) && ( event.key.keysym.unicode <= (Uint16)'9' ) )
{
//Append the character
str += (char)event.key.keysym.unicode;
}
//If the key is a uppercase letter
else if( ( event.key.keysym.unicode >= (Uint16)'A' ) && ( event.key.keysym.unicode <= (Uint16)'Z' ) )
{
//Append the character
str += (char)event.key.keysym.unicode;
}
//If the key is a lowercase letter
else if( ( event.key.keysym.unicode >= (Uint16)'a' ) && ( event.key.keysym.unicode <= (Uint16)'z' ) )
{
//Append the character
str += (char)event.key.keysym.unicode;
}
if ( (( event.key.keysym.sym == SDLK_BACKSPACE ) && ( str.length() != 0 )) ){
str.erase( str.length() - 1 );
}
strcpy (pars, str.c_str());
if( str != temp ){
draw();
}
}
if (event.key.keysym.sym==SDLK_F1){
music_v-=2;
music_v2=music_v;
Mix_VolumeMusic(music_v);
}
if (event.key.keysym.sym==SDLK_F2){
music_v+=2;
music_v2=music_v;
Mix_VolumeMusic(music_v);
}
if ( event.type == SDL_KEYDOWN && event.key.keysym.sym==SDLK_F3){
music_vm++;
if (music_vm%2==0)
music_v=music_v2;
if (music_vm%2==1){
music_v2=music_v;
music_v=0;}
Mix_VolumeMusic(music_v);
}
if ( event.type == SDL_KEYDOWN && event.key.keysym.sym==SDLK_TAB){
if (m_flashl_%2==0){
m_flashl=false;
m_flashl_--;}
else{
m_flashl=true;
m_flashl_++;}
draw();
loop++;
}
//If the enter key was pressed
if( ( event.type == SDL_KEYDOWN ) && ( event.key.keysym.sym == SDLK_RETURN ) ){
//loop=0;
str2 = str;
// str.erase( remove(str.begin(), str.end() ' '), str.end() );
if (str.length()!=0){
str=str2;
for(int i = 0; pars[ i ]; i++){
pars[i] = tolower(pars[ i ]);
}
char *ptr = strtok(pars," ");
int pars_loop=1;
if (multiple_doors==false){
word_1=0;
article=0;
adjective=0;
takeobj=0;
we_door=0;
dir_adj=0;
}
int and_count=0;
/* WORD_1
0=no value
1=movement (combines with n,s,e,w, "separated" by type: 11=go 12=run (13=sneak?)
11=go
12=run
2=action (will be "separated" in 21, 22 23.... 29)
21=look look to a direction
22=take
23=grab
24=use
25=open
26=unlock
*/
/* ARTICLE
0=no value
1=take/grab the
11=open the
12=unlock the
13=use the
2=take/grab a
? 3=take/grab some
*/
/*
ADJECTIVE
0=no value
1=BLUE
11=PURPLE
12=YELLOW
13=GREEN
14=LIGHT BLUE
TAKEOBJ
1=take the key 11=take the key to
DIRECTION ADJECTIVE dir_adj
0=off
1=w
2=e
3=n
4=s
*/
while (ptr!=NULL){
if ((strcmp(ptr, "and")==0)){
if (pars_loop>=2 && and_count==0){
and_count++;
b = a;
pars_loop=0;
abswitch = true;
mess2=true;
}
if (pars_loop>=2 && and_count==1){
//and_count++;
c = b;
b = a;
pars_loop=0;
abcswitch = true;
mess2=true;
mess3=true;
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true; //missed word
}
if ((strcmp(ptr, "to")==0)){
if (pars_loop>=1){
if (takeobj==1){
takeobj=11;
pars_loop=0;
}
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
if ((strcmp(ptr, "the")==0)){
if (pars_loop>=2){
pars_loop=0;
if (word_1==22 || word_1==23)
article=1;
if (word_1==24)
article=13;
if (word_1==25)
article=11;
if (word_1==26)
article=12;
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
if ((strcmp(ptr, "blue")==0)){
if (pars_loop>=1){
pars_loop=0;
if ((word_1==22 || word_1==23) && (article==1 || article==0 ) && light==false)
adjective=1;
if ((word_1==22 || word_1==23) && (article==1 || article==0 ) && light==true)
adjective=14;
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
if ((strcmp(ptr, "purple")==0)){
if (pars_loop>=1){
pars_loop=0;
if ((word_1==22 || word_1==23) && (article==1 || article==0 ))
adjective=11;
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
if ((strcmp(ptr, "yellow")==0)){
if (pars_loop>=1){
pars_loop=0;
if ((word_1==22 || word_1==23) && (article==1 || article==0 ))
adjective=12;
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
if ((strcmp(ptr, "green")==0)){
if (pars_loop>=1){
pars_loop=0;
if ((word_1==22 || word_1==23) && (article==1 || article==0 ))
adjective=13;
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
if ((strcmp(ptr, "light")==0)){
if (pars_loop>=1){
pars_loop=0;
light=true;
}
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
if (menu_1==true){
if (pars_loop==1) {
if ((strcmp(ptr, "start")==0)){
a= "Then lets start!";
room1=true;
showtext=true;
txterr=false;
parsing=false;
misswo=false;
pars_loop=0;
}
else if ((strcmp(ptr, "quit")==0)){
Mix_HaltMusic();
a= "Quitting...";
mess2=false; mess3=false;
quit = true;
nameEntered=true;
draw();
SDL_Delay (1500);
}
else {
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
}
}
}
if (parsing==true){
if ((strcmp(ptr, "go")==0)){
if (pars_loop==1){
a= "Where?!";
word_1=11;
misswo=true;
}
if (pars_loop==2){
a = "You should learn English grammar... ";
misswo=true;
}
}
else if ((strcmp(ptr, "run")==0)){
if (pars_loop==1){
a= "Where?!";
word_1=12;
misswo=true;
}
if (pars_loop==2){
a = "You should learn English grammar... ";
misswo=true;
}
}
else if (strcmp(ptr, "take")==0){
if (pars_loop==1){
a = "What?!";
word_1=22;
misswo=true;
}
if (pars_loop==2){
a = "\"I don't mean to sound slutty, but please use me anytime you want!\" - Sincerely, the English Grammar";
misswo=false;
}
}
else if (strcmp(ptr, "grab")==0){
if (pars_loop==1){
a = "What?!";
word_1=23;
misswo=true;
}
if (pars_loop==2){
a = "\"I don't mean to sound slutty, but please use me anytime you want!\" - Sincerely, the English Grammar";
misswo=false;
}
}
else if (strcmp(ptr, "look")==0){
if (pars_loop==1){
word_1=21;
lookar=true;
misswo=false;
showtext=true;
txterr=false;
}
if (pars_loop==2){
a = "\"I don't mean to sound slutty, but please use me anytime you want!\" - Sincerely, the English Grammar";
misswo=false;
}
}
else if (strcmp(ptr, "use")==0){
if (pars_loop==1){
word_1=24;
misswo=false;
showtext=true;
txterr=false;
}
if (pars_loop==2){
a = "\"I don't mean to sound slutty, but please use me anytime you want!\" - Sincerely, the English Grammar";
misswo=false;
}
}
else if (strcmp(ptr, "open")==0){
if (pars_loop==1){
word_1=25;
misswo=false;
showtext=true;
txterr=false;
}
if (pars_loop==2){
a = "\"I don't mean to sound slutty, but please use me anytime you want!\" - Sincerely, the English Grammar";
misswo=false;
}
}
else if (strcmp(ptr, "unlock")==0){
if (pars_loop==1){
word_1=26;
misswo=false;
showtext=true;
txterr=false;
}
if (pars_loop==2){
a = "\"I don't mean to sound slutty, but please use me anytime you want!\" - Sincerely, the English Grammar";
misswo=false;
}
}
else if ((strcmp(ptr, "north")==0) || strcmp(ptr, "n")==0){
if (pars_loop==1){
if (multiple_doors==false){
a = "I can't find a verb...";
misswo=true;}
if (multiple_doors==true){
we_door=3;
multiple_doors_q=true;
}
}
if (pars_loop==2 && (word_1==11 || word_1==12)){
if (n==0){
if (word_1==11)
a = "Going north... ";
if (word_1==12)
a = "Running north... ";
n=1;
misswo=false;
showtext=true;
txterr=false;
}
if (n==2){
a="I can't go that way...";
misswo=true;
}
}
}
else if ((strcmp(ptr, "south")==0) || strcmp(ptr, "s")==0){
if (pars_loop==1){
if (multiple_doors==false){
a = "I can't find a verb...";
misswo=true;}
if (multiple_doors==true){
we_door=4;
multiple_doors_q=true;
}
}
if (pars_loop==2 && (word_1==11 || word_1==12)){
if (s==0){
if (word_1==11)
a = "Going south... ";
if (word_1==12)
a = "Running south... ";
s=1;
misswo=false;
showtext=true;
txterr=false;
}
if (s==2){
a="I can't go that way...";
misswo=true;
}
}
}
else if ((strcmp(ptr, "east")==0) || strcmp(ptr, "e")==0){
if (pars_loop==1){
if (multiple_doors==false){
a = "I can't find a verb...";
misswo=true;}
if (multiple_doors==true && room2a==true){
multiple_doors_q=true;
}
if (word_1==25){
we_door=2;
if (room2a==true && r3_doorun==true && pl_key==true)
r3_doorop=1;
}
if (word_1==26){
we_door=2;
if (room2a==true && pl_key==true)
r3_doorun=true;
}
if ((article==11 || article==12 || article==0) && (word_1==25 || word_1==26) && multiple_doors==false && we_door==0){
dir_adj=2;
multiple_doors_q=true;
}
}
if (pars_loop==2 && (word_1==11 || word_1==12)){
if (e==0){
if (word_1==11)
a = "Going east... ";
if (word_1==12)
a = "Running east... ";
e=1;
misswo=false;
showtext=true;
txterr=false;
}
if (e==2){
a="I can't go that way...";
misswo=true;
}
}
}
else if ((strcmp(ptr, "west")==0) || strcmp(ptr, "w")==0){
if (pars_loop==1){
if (multiple_doors==false){
a = "I can't find a verb...";
misswo=true;}
if (multiple_doors==true && room2a==true){
we_door=1;
multiple_doors_q=true;
}
}
if (pars_loop==2 &&(word_1==11 || word_1==12)){
if (w==0){
if (word_1==11)
a = "Going west... ";
if (word_1==12)
a = "Running west... ";
w=1;
misswo=false;
showtext=true;
txterr=false;
}
if (w==2){
a="I can't go that way...";
misswo=true;
}
}
}
else if (( strcmp(ptr, "key")==0 /*|| strcmp(ptr, "keys")==0*/ )){
if (room1==true || room2a==true || room3==true || room4==true || room6==true){
if (k_roomin==1 && (article==1 || article==0 )){
a="There is no key to ";
if (word_1==22)
a=a+"take...";
if (word_1==23)
a=a+"grab...";
}
if ((word_1==22 || word_1==23 ) && (article==1 || article==0 ) && adjective==0 && k_roomin==0){
if (word_1==22)
a="You take the key";
if (word_1==23)
a="You grab the key";
if (room1==true)
b_key=true;
if (room2a==true)
pl_key=true;
if (room3==true)
y_key=true;
if (room4==true)
g_key=true;
if (room6==true)
lb_key=true;
k_roomin=1;
}
if ((word_1==22 || word_1==23 ) && (article==1 || article==0 ) && adjective>=1 && adjective<=14 && k_roomin==0){
if (word_1==22)
a="You take the ";
if (word_1==23)
a="You grab the ";
if (adjective==1 && room1==true){
k_roomin=1;
a=a+"blue";
b_key=true;
}
if (adjective==11 && room2a==true){
a=a+"purple";
k_roomin=1;
pl_key=true;
}
if (adjective==12 && room3==true){
a=a+"yellow";
y_key=true;
k_roomin=1;
}
if (adjective==13 && room4==true){
a=a+"green";
g_key=true;
k_roomin=1;
}
if (adjective==14 && room6==true){
a=a+"light blue";
k_roomin=1;
lb_key=true;
}
a=a+" key";
adjective=0;
}
if (k_roomin!=1){
a = "I see no ";
if (adjective==1)
a=a+"blue";
if (adjective==11)
a=a+"purple";
if (adjective==12)
a=a+"yellow";
if (adjective==13)
a=a+"green";
if (adjective==14)
a=a+"light blue";
a=a+" key";
adjective=0;
}
if (word_1==24 && (article==13 || article==0)){ //use
if (room1==true)
takeobj=1;
if (room2a==true)
takeobj=1;
a="To do WHAT?!";
}
}
}
else if ((strcmp(ptr, "door")==0) || (multiple_doors==true && we_door>0 && room2a==true)){
if ((article==11 || article==12 || article==0) && (word_1==25 || word_1==26) && dir_adj==2){
if ((article==11 || article==0) && word_1==25 ){
if (room2a==true && r3_doorun==true)
a="You open the east door..."; r3_doorop=1;
}
if ((article==12 || article==0) && word_1==26 ){
if (room2a==true)
a="You unlock the east door..."; r3_doorun=true;
}
}
if ((word_1==25 && (article==11 || article==0)) || (multiple_doors==true && we_door>0 && room2a==true)){ //open
if (room1==true){
if (r1_doorun==false)
a="You can't, the door is locked...";
if (r1_doorun==true){
a="You open the door...";
r1_doorop=1;
}
if (takeobj==11){
a="You use the key to open the door...";
r1_doorun=true;
r1_doorop=1;
}
}
if (room2a==true){
if (multiple_doors_q==false && we_door==0){
a="Which one, west or east?";
multiple_doors=true;
nameEntered=false;
}
if (we_door==2){
multiple_doors=false;
if (r3_doorun==false)
a="You can't, the door is locked...";
if (r3_doorun==true){
a="You open the door...";
r3_doorop=1;
}
if (takeobj==11){
a="You use the key to open the door...";
r3_doorun=true;
r3_doorop=1;
}
}
}
}
if ((word_1==26 && (article==12 || article==0)) || (multiple_doors==true && we_door>0 && room2a==true && dir_adj==0)){ //unlock
if (room1==true){
if (b_key==true){
a="You unlock the door...";
r1_doorun=true;
r1_doorop=1;
}
if (b_key==false)
a="You don't have the key...";
if (takeobj==11){
a="You use the key to unlock the door...";
r1_doorun=true;
}
}
if (room2a==true){
if (multiple_doors_q==false && we_door==0){
a="Which one, west or east?";
multiple_doors=true;
nameEntered=false;
}
if (we_door==2){
multiple_doors=false;
if (pl_key==true){
a="You unlock the east door...";
r3_doorun=true;
}
if (pl_key==false)
a="This door is locked and you don't have the key...";
if (takeobj==11){
a="You use the key to unlock the east door...";
r3_doorun=true;
takeobj=0;
}
}
}
}
}
else if (strcmp(ptr, "quit")==0){
Mix_HaltMusic();
a= "Quitting...";
quit = true;
nameEntered=true;
mess2=false; mess3=false;
draw();
SDL_Delay (1500);
}
else {
a = "I'm sorry, I don't understand what you mean...";
misswo=true;
if (pars_loop==1){
str3=ptr;
a = "I don't know what \"" + str3 + "\" means...";
}
}
pars_loop++;
}
if (misswo==true){
nameEntered=false;
loop=0;
showtext=true;
txterr=true;
}
all_rooms();
if (pars_loop==0)
pars_loop++;
ptr = strtok(NULL, " ");
}
mess1=true;
}
if (str.length()==0){
b="You wrote nothing!";
if (menu_1==true){
a=b;
nameEntered=false;
mess2=false;
mess3=false;
loop=0;
showtext=true;
}
else {
nameEntered=false;
mess2=true;
loop=0;
showtext=true;
}
}
}
if( ( event.type == SDL_KEYDOWN ) && ( event.key.keysym.sym == SDLK_ESCAPE ) ){
Mix_HaltMusic();
a= "Quitting...";
mess2=false; mess3=false;
quit = true;
nameEntered=true;
draw();
SDL_Delay (1500);
}
if( event.type == SDL_QUIT ){
Mix_HaltMusic();
//Quit the program
quit = true;
nameEntered=true;
}
if (loop==0){
draw();
loop++;
}
}
}
if(1000/60>(SDL_GetTicks()-start))
SDL_Delay(1000/60-(SDL_GetTicks()-start));
if( event.type == SDL_QUIT ){
Mix_HaltMusic();
quit = true; }
}
SDL_Quit();
return 0;
}
Rooms.h
#include "init.h"
//ROOMS!!! && BOOLS!!!!
bool room1=false;
bool room2=false;
bool room2a=false;
bool room2b=false;
bool room3=false;
bool room4=false;
bool room5=false;
bool room6=false;
bool menu_1=true;
bool nameEntered = false;
bool parsing=false;
bool txterr=false;
bool misswo=false;
bool lookar=false;
int word_1=0;
int article=0;
int adjective=0;
int takeobj=0;
int dir_adj=0;
bool multiple_doors=false;
bool multiple_doors_q=false;
bool noparsloop=false;
int n=2;
int s=2;
int w=2;
int e=2;
void menu(){
//Set the message
a = "Type:";
b = "\"Start\" to start the game; Press Escape or write \"Quit\" to quit the game;";
c = "Use F1/F2 to lower/raise the volume, F3 to mute/unmute!";
mess1=true;
mess2=true;
mess3=true;
menu_1=true;
parsing=false;
}
void room_1(){
mess2 =false; mess3 = false;
menu_1=false;
room_look= "Room 1";
background = loadTexture("Room1.png");
n=2;//2 = can't go
s=2;
e=2;
w=0;// 0 = can go
k_roomin=0;
if (b_key==true)
k_roomin=1;
}
void room_2(){
room_look= "Room 2";
background = loadTexture("Scalpel.png");
n=0;
s=2;
e=0;
w=0;
k_roomin=0;
}
void room_2a(){
room_look= "Room 2a";
background = loadTexture("Room1.png");
n=2;
s=0;
e=0;
w=0;
k_roomin=0;
if (pl_key==true)
k_roomin=1;
}
void room_2b(){
room_look= "Room 2b";
background = loadTexture("Room1.png");
n=0;
s=0;
e=0;
w=2;
k_roomin=0;
if (lb_key==true)
k_roomin=1;
}
void room_3(){
room_look= "Room 3";
background = loadTexture("Scalpel.png");
n=2;
s=2;
e=2;
w=0;
k_roomin=0;
}
void room_5(){
room_look= "Room 5";
background = loadTexture("Scalpel.png");
n=2;
s=2;
e=0;
w=2;
k_roomin=0;
if (g_key==true)
k_roomin=1;
}
void room_4(){
room_look= "Room 4";
background = loadTexture("Room1.png");
n=2;
s=0;
e=2;
w=2;
k_roomin=0;
if (y_key==true)
k_roomin=1;
}
void room_6(){
room_look= "Room 6";
background = loadTexture("Room1.png");
n=2;
s=2;
e=0;
w=2;
k_roomin=0;
}
void room_end(){
room_look= "THE END!";
background = loadTexture("Room1.png");
n=2;
s=2;
e=2;
w=0;
k_roomin=0;
}
void all_rooms(){
if (str.length()!=0 && txterr==false){
if (room1==true && (w==0 || w==2)){
room1=true;
room_1();
}
if (room1==true && w==1){
if (r1_doorun==true && r1_doorop==1 ){
room1=false;
room2=true;
room_2();
}
if (r1_doorop==0){
room_1();
a="The door is closed...";
}
if (r1_doorun==false){
room_1();
a="The door is locked, you need a key...";
}
}
if (room2==true && w==1){
room2=false;
room2b=true;
room_2b();
}
if (room2==true && e==1){
room2=false;
room1=true;
room_1();
}
if (room2==true && n==1){
room2=false;
room2a=true;
room_2a();
}
if (room2a==true && s==1){
room2a=false;
room2=true;
room_2();
}
if (room2a==true && e==1){
if (r3_doorun==true && r3_doorop==1){
room2a=false;
room3=true;
room_3();
}
if (r3_doorop==0){
room_2a();
a="The door is closed...";
}
if (r3_doorun==false){
room_2a();
a="The door is locked, you need a key...";
}
}
if (room2a==true && w==1){
room2a=false;
room5=true;
room_5();
}
if (room2b==true && e==1){
room2b=false;
room2=true;
room_2();
}
if (room3==true && w==1){
room3=false;
room2a=true;
room_2a();
}
if (room5==true && e==1){
room5=false;
room2a=true;
room_2a();
}
if (lookar==true){
a=room_look;
lookar=false;
}
parsing=true;
nameEntered = false;
loop=0;
showtext=true;
}
}
//END OF ROOMS
Init.h
#ifdef __linux__
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_opengl.h"
#include "SDL/SDL_mixer.h"
#else
#include "SDL.h"
#include "SDL_opengl.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include "SDL_mixer.h"
#endif
#include <stdio.h>
#include <string>
#include <cstring>
#include <fstream>
#include <iostream>
#include <time.h>
#include <cmath>
using namespace std;
int background;
int console;
GLuint glmessage;
GLuint glmessage2;
GLuint glmessage3;
SDL_Surface *message=NULL;
SDL_Surface *message2=NULL;
SDL_Surface *message3=NULL;
SDL_Surface *text=NULL;
int gltext;
int screen;
int overlay;
int shadow;
int m_flash;
char pars[100];
int loop=0;
bool showtext=true;
bool abswitch = false;
bool abcswitch = false;
bool holdd=false;
bool b_key=false;
bool pl_key=false;
bool y_key=false;
bool lb_key=false;
bool g_key=false;
bool mess1=false;
bool mess2=false;
bool mess3=false;
bool r1_doorun=false;
bool r3_doorun=false;
bool r4_doorun=false;
bool r6_doorun=false;
int r1_doorop=0;
int r3_doorop=0;
int r4_doorop=0;
int r6_doorop=0;
bool light=false;
bool m_flashl=false;
int m_flashl_=1; //flashlight
int we_door=0; //west or east door chose 0=inactive 1=west 2=east 3=north 4=south
int k_roomin=0; // 0=no key of the room you are in 1=you have the key of the room you're in
bool keys[323]={false};
int music_v=32;
int music_v2;
int music_vm=0;
int m_x=0, m_y=0;
//Quit flag
bool quit = false;
//The music that will be played
Mix_Music *music;
//The storage strings for console instrucitions
string str;
string str2;
string str3;
string a;
string b;
string c;
string room_look;
//The event structure
SDL_Event event;
//The font
TTF_Font *font;
TTF_Font *fontv2;
//The color of the font
SDL_Color textColor = { 255, 0, 0};
void RenderText(const TTF_Font *Font, const GLubyte& R, const GLubyte& G, const GLubyte& B,
const double& X, const double& Y, const double& Z, const std::string& Text)
{
/*Create some variables.*/
SDL_Color Color = {R, G, B};
SDL_Surface *Message = TTF_RenderText_Blended(const_cast<TTF_Font*>(Font), Text.c_str(), Color);
unsigned Texture = 0;
/*Generate an OpenGL 2D texture from the SDL_Surface*.*/
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Message->w, Message->h, 0, GL_BGRA,
GL_UNSIGNED_BYTE, Message->pixels);
/*Draw this texture on a quad with the given xyz coordinates.*/
glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex3d(X, Y, Z);
glTexCoord2d(1, 0); glVertex3d(X+Message->w, Y, Z);
glTexCoord2d(1, 1); glVertex3d(X+Message->w, Y+Message->h, Z);
glTexCoord2d(0, 1); glVertex3d(X, Y+Message->h, Z);
glEnd();
/*Clean up.*/
glDeleteTextures(1, &Texture);
SDL_FreeSurface(Message);
}
void FillRect(int x, int y, int w, int h, int c1, int c2, int c3) {
int f_rect=0;
glBindTexture(GL_TEXTURE_2D, f_rect);
glColor3f ((double)c1/255, (double)c2/255, (double)c3/255);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(x, y-h);
glTexCoord2f(1,0); glVertex2f(x+w,y-h);
glTexCoord2f(1,1); glVertex2f(x+w, y);
glTexCoord2f(0,1); glVertex2f(x, y);
glEnd();
SDL_GL_SwapBuffers();
}
int loadTexture(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_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
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_BGRA_EXT,GL_UNSIGNED_BYTE,image->pixels);
SDL_FreeSurface(image);
return object;
}
void init(){
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
srand(time(NULL));
/* Initialization */
SDL_InitSubSystem(SDL_INIT_AUDIO);
SDL_EnableKeyRepeat(250, 100);
//Initialize SDL_mixer
Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 4096 );
TTF_Init();
music = Mix_LoadMUS( "LT.ogg" );
//Open the font
font = TTF_OpenFont( "menlo.ttc", 12 );
fontv2 = TTF_OpenFont( "menlo.ttc", 20 );
SDL_EnableUNICODE( SDL_ENABLE );
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,1024,740,1.0, 0.0,1.0);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
background=loadTexture("Scalpel.png");
console=loadTexture("console.png");
shadow=loadTexture("BBB.png");
}
void draw(){
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D,background);
//glColor4f ((double)255/255, (double)255/255, (double)255/255, (double)100/255);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(0,0);
glTexCoord2f(1,0); glVertex2f(1024,0);
glTexCoord2f(1,1); glVertex2f(1024,600);
glTexCoord2f(0,1); glVertex2f(0,600);
glEnd();
glBindTexture(GL_TEXTURE_2D, overlay);
glColor4f ((double)0/255, (double)0/255, (double)0/255, 0.80f);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(0,0);
glTexCoord2f(1,0); glVertex2f(1024,0);
glTexCoord2f(1,1); glVertex2f(1024,740);
glTexCoord2f(0,1); glVertex2f(0,740);
glEnd();
if (m_flashl==true){
glBindTexture(GL_TEXTURE_2D, shadow);
//glColor4f ((double)255/255, (double)255/255, (double)255/255, 0.25f);
//glColor3f(1.0f, 1.0f, 1.0f);
glColor4f(1, 1, 1, 0.1f);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(m_x-150, m_y-150);
glTexCoord2f(1,0); glVertex2f(m_x+150, m_y-150);
glTexCoord2f(1,1); glVertex2f(m_x+150, m_y+150);
glTexCoord2f(0,1); glVertex2f(m_x-150, m_y+150);
glEnd();}
glBindTexture(GL_TEXTURE_2D, console);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(0,595);
glTexCoord2f(1,0); glVertex2f(1024,595);
glTexCoord2f(1,1); glVertex2f(1024,595+156);
glTexCoord2f(0,1); glVertex2f(0,595+156);
glEnd();
if (mess1==true)
RenderText(font, 255, 0, 0, 35, 630+12, NULL, a.c_str());
if (mess2==true)
RenderText(font, 255, 0, 0, 35, 646+12, NULL, b.c_str());
if (mess3==true)
RenderText(font, 255, 0, 0, 35, 662+12, NULL, c.c_str());
if (str.length()!=0){
RenderText(font, 255, 0, 0, 35, 694+12, NULL, str.c_str());
}
glFlush();
SDL_GL_SwapBuffers();
}
I apologize if you might find the code hard to read, I have some problems with commenting but I am trying to get better at it
Thanks for any help