7
« on: June 09, 2009, 04:21:00 pm »
Hello
First i create the app window, and then send the window to another class that are supposed to draw something on it.But the window is blank when i run the program.
I can see the image if I make some ugly code and draw an image in the main loop.
#include "SDL.h"
#include <string>
#include "Window.h"
#include "Model.h"
#include "SDL_mixer.h"
#include "SDL_ttf.h"
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/System.hpp>
using namespace std;
int main( int argc, char* args[] )
{
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return 1;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 ){
return false;
}
Mix_OpenAudio( 44000, MIX_DEFAULT_FORMAT, 2, 4096 );
sf::RenderWindow *app;
app = new sf::RenderWindow(sf::VideoMode(800, 600), "SFML window");
//(sf::VideoMode(800, 600), "SFML window");
Model *model = new Model();
// Window *theWindow = new Window(800,600,model);
SDL_Event event;
bool keysHeld[10] = {false};
// bool keyPulses[10];
// keyPulses[4] = true;
long start;
// SDL_ShowCursor(SDL_DISABLE);
sf::Image Image;
Image.LoadFromFile("backgrounds/selectscreen.bmp");
sf::Sprite Sprite1;
Sprite1.SetImage(Image);
// Sprite(Image);
while( model->quitcheck() == false )
{
//If there's an event to handle
if( SDL_PollEvent( &event ) )
{
//If a key was pressed
if( event.type == SDL_KEYDOWN )
{
switch(event.key.keysym.sym) {
case SDLK_LEFT:
keysHeld[0] = true;
break;
case SDLK_RIGHT:
keysHeld[1] = true;
break;
case SDLK_UP:
keysHeld[2] = true;
break;
case SDLK_DOWN:
keysHeld[3] = true;
break;
case SDLK_RETURN:
// if (keyPulses[4] == true){
keysHeld[4] = true;
// keyPulses[4] = false;
// }
break;
case SDLK_ESCAPE:
keysHeld[5]= true;
break;
}
}
if( event.type == SDL_KEYUP )
{
switch(event.key.keysym.sym) {
case SDLK_LEFT:
keysHeld[0] = false;
break;
case SDLK_RIGHT:
keysHeld[1] = false;
break;
case SDLK_UP:
keysHeld[2] = false;
break;
case SDLK_DOWN:
keysHeld[3] = false;
break;
case SDLK_RETURN:
keysHeld[4] = false;
// keyPulses[4] = true;
break;
case SDLK_ESCAPE:
keysHeld[5] = false;
break;
}
}
}
start = SDL_GetTicks();
model->handleinput(keysHeld);
model->updateGame();
model->drawAll(app);
// app->Draw(Sprite1);
app->Display();
// theWindow->draw();
while((start + 16.67) > SDL_GetTicks()){
}
}
SDL_Quit();
return 0;
}
void Model::drawAll(sf::RenderWindow *screenen){
gamestate->drawStagelow(screenen);
}
// Selectscreen is a subclass to gamestate
void SelectScreen::drawStagelow(sf::RenderWindow *screenen){
screenen->Draw(background1);
// apply_surface(offsetbackground.x,offsetbackground.y,background,screenen,&test);
// apply_surface(offsetstart.x - test.x,offsetstart.y, startbutton,screenen,&test);
// apply_surface(offsetquit.x - test.x,offsetquit.y, quitbutton,screenen,&test);
// apply_surface(offsetunderline.x - test.x,offsetunderline.y, buttonunderline,screenen,&test);
// apply_surface(offsetcontinue.x - test.x,offsetcontinue.y, continuebutton,screenen,&test);
// apply_surface(offsetoptions.x - test.x,offsetoptions.y, optionsbutton,screenen,&test);
}