// *************************************************************************** // PUCRS/FACIN // Curso de Especialização em Desenvolvimento de Jogos Digitais // Computação Gráfica 2D // Profs. // Isabel Harb Manssour / Márcio Sarroglia Pinho // *************************************************************************** #include #include #include #include #include #include using namespace std; #ifdef __APPLE__ #include #include #include #else #include #include #include #endif #include "CImage.h" CImage *Img1 = NULL; vector sprite; int currentFrame = 0; float posX = 0; void Desenha(int w, int h) { cout << "DESENHA: Largura: " << w << " - Altura: " << h << endl; glClearColor(0, 0, 1, 0); // a cor do fundo glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, h, 0, 1, -1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, w, h); glEnable(GL_TEXTURE_2D); // isto é necessário quando se deseja desenhar com texturas glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1,1,0); glLineWidth(3); glBegin(GL_LINES); glVertex2i(0,100); glVertex2i(100,100); glEnd(); SDL_GL_SwapBuffers(); } void CarregaImagem() { } void CarregaSprite() { } int main( int argc, char* args[] ) { //Start SDL SDL_Init( SDL_INIT_EVERYTHING ); // Define o titulo da janela SDL_WM_SetCaption("Jogo", "Jogo Basico - Minimizado"); // Request double-buffered OpenGL SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); // create a new window on screen int flags = SDL_OPENGL | SDL_RESIZABLE ; SDL_Surface* screen = SDL_SetVideoMode(300, 400, 32, flags); if ( !screen ) { printf("Impossivel inicializar a janela. Erro: %s\n", SDL_GetError()); getchar(); return 1; } else { cout << "Janela Inicializada !" << endl; cout << "Largura: " << screen->w << " - Altura: " << screen->h << endl; } CarregaImagem(); CarregaSprite(); cout << "Inicio do Laco de Render" << endl; // main loop bool done = false; bool precisaRedesenhar = true; // Inicializa contador de tempo. // enable automatic key repetition SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); while (!done) { // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; cout << "Tentando fechar" << endl; break; case SDL_KEYDOWN: cout << "Tecla: " << event.key.keysym.sym << endl; // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) { done = true; break; } else if (event.key.keysym.sym == 276) { // LEFT ARROW cout << "Tecla ESQUERDA"<< endl; } else if (event.key.keysym.sym == SDLK_RIGHT) { posX++; precisaRedesenhar = true; } // SDL_APPACTIVE: When the application is either minimized/iconified // (gain=0) or restored ('gain'=1) this type of activation event occurs case SDL_APPACTIVE: if (event.active.gain==0) { precisaRedesenhar = true; } break; case SDL_VIDEORESIZE: cout << "Janela alterada !" << endl; SDL_Surface* screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32, flags); precisaRedesenhar = true; break; } // end switch }// end of message processing if (precisaRedesenhar) Desenha(screen->w, screen->h); precisaRedesenhar = false; } // do while cout << "Programa Encerrando..." << endl; SDL_Quit(); return 0; }