Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. //Noman Hamlani
  2. //N16943203
  3. //CS3313
  4. //Asignment 1
  5.  
  6. #ifdef _WINDOWS
  7. #include <GL/glew.h>
  8. #endif
  9.  
  10. #include <SDL.h>
  11. #include <SDL_opengl.h>
  12. #include <SDL_image.h>
  13. #include "Matrix.h"
  14. #include "ShaderProgram.h"
  15.  
  16. #ifdef _WINDOWS
  17. #define RESOURCE_FOLDER ""
  18. #else
  19. #define RESOURCE_FOLDER "NYUCodebase.app/Contents/Resources/"
  20. #endif
  21.  
  22. SDL_Window *displayWindow;
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.     SDL_Init(SDL_INIT_VIDEO);
  27.     displayWindow = SDL_CreateWindow("Noman Hamlani - Assignement 2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 360, SDL_WINDOW_OPENGL);
  28.     SDL_GLContext context = SDL_GL_CreateContext(displayWindow);
  29.     SDL_GL_MakeCurrent(displayWindow, context);
  30.  
  31. #ifdef _WINDOWS
  32.     glewInit();
  33. #endif
  34.  
  35.     // setup
  36.     glViewport(0, 0, 640, 360);
  37.     ShaderProgram program(RESOURCE_FOLDER"vertex_textured.glsl", RESOURCE_FOLDER"fragment_textured.glsl");
  38.  
  39.     Matrix projection_matrix;
  40.     Matrix model_matrix;
  41.     Matrix view_matrix;
  42.  
  43.     projection_matrix.setOrthoProjection(-3.55f, 3.55f, -2.0f, 2.0f, -1.0f, 1.0f);
  44.  
  45.     SDL_Event event;
  46.     bool done = false;
  47.     while (!done) {
  48.         while (SDL_PollEvent(&event)) {
  49.             if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
  50.                 done = true;
  51.             }
  52.         }
  53.  
  54.         program.setModelMatrix(model_matrix);
  55.         program.setProjectionMatrix(projection_matrix);
  56.         program.setViewMatrix(view_matrix);
  57.  
  58.         glClear(GL_COLOR_BUFFER_BIT);
  59.  
  60.         glUseProgram(program.programID);
  61.  
  62.         float shipVertices[] = { -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5 };
  63.         glVertexAttribPointer(program.positionAttribute, 2, GL_FLOAT, false, 0, shipVertices);
  64.         glEnableVertexAttribArray(program.positionAttribute);
  65.  
  66.         glDrawArrays(GL_TRIANGLES, 0, 6);
  67.         glDisableVertexAttribArray(program.positionAttribute);
  68.  
  69.         SDL_GL_SwapWindow(displayWindow);
  70.     }
  71.  
  72.     SDL_Quit();
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement