Advertisement
rodrigofbm

main.cpp

Jan 31st, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. #include <SDL.h>
  2. #include "SDL_opengl.h"
  3.  
  4. int main(int argv, char** args){
  5.  
  6.     SDL_Init(SDL_INIT_EVERYTHING);
  7.     //Inicio do escopo
  8.  
  9.         //memoria
  10.         SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
  11.         SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
  12.         SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
  13.         SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
  14.         SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
  15.         SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
  16.         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  17.  
  18.         //nome da janela
  19.         SDL_WM_SetCaption("Meu Primeiro Jogo em C++", NULL);
  20.         SDL_SetVideoMode(600, 400, 32, SDL_OPENGL);
  21.  
  22.         //cor da janela
  23.         glClearColor(1,1,1,1);
  24.  
  25.         //area exebida
  26.         glViewport(0,0,600,400);
  27.  
  28.         //sombra
  29.         glShadeModel(GL_SMOOTH);
  30.  
  31.         //2D
  32.         glMatrixMode(GL_PROJECTION); //aplicar projecao na matriz atual
  33.         glLoadIdentity();//desenho geometrico
  34.  
  35.         glDisable(GL_DEPTH_TEST);
  36.  
  37.         //variaveis
  38.         bool executando = true;
  39.         SDL_Event eventos;
  40.         //loop
  41.         while(executando){
  42.             //eventos
  43.             while(SDL_PollEvent(&eventos)){
  44.                 //fecha com o x da janela
  45.                 if(eventos.type == SDL_QUIT)
  46.                     executando = false;
  47.  
  48.                 /*if(eventos.type == SDL_KEYUP && eventos.key.keysym.sym == SDLK_ESCAPE)
  49.                     executando = false;*/
  50.             }
  51.  
  52.             //LOGICA:
  53.  
  54.  
  55.             //RENDERIZACAO
  56.  
  57.             glClear(GL_COLOR_BUFFER_BIT);//limpar o buffer
  58.  
  59.             //inicia matriz
  60.             glPushMatrix();
  61.                 //dimensoes da matriz
  62.                 glOrtho(0, 600, 400, 0, -1, -1);
  63.                 //cor
  64.                 glColor4ub(255, 0, 0, 255); //linha vermelha
  65.  
  66.                 //inicia o desenho
  67.                 glBegin(GL_LINES);//GL_POINTS, GL_LINES, GL_LINES_LOOP, GL_QUADS, GL_TRIANGLES, GL_POLIGON
  68.                     glVertex2f(50, 50);
  69.                     glVertex2f(550, 350);
  70.  
  71.  
  72.                 //fecha o desenho
  73.                 glEnd();
  74.  
  75.             //fecha matriz
  76.             glPopMatrix();
  77.  
  78.             //animacao
  79.             SDL_GL_SwapBuffers();
  80.         }
  81.  
  82.  
  83.         glDisable(GL_BLEND);
  84.  
  85.  
  86.     //SDL_Delay(5000);
  87.  
  88.     //Fim do escopo
  89.     SDL_Quit();
  90.  
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement