Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Noman Hamlani
- //N16943203
- //CS3313
- //Asignment 1
- #ifdef _WINDOWS
- #include <GL/glew.h>
- #endif
- #include <SDL.h>
- #include <SDL_opengl.h>
- #include <SDL_image.h>
- #include "Matrix.h"
- #include "ShaderProgram.h"
- #ifdef _WINDOWS
- #define RESOURCE_FOLDER ""
- #else
- #define RESOURCE_FOLDER "NYUCodebase.app/Contents/Resources/"
- #endif
- SDL_Window *displayWindow;
- int main(int argc, char *argv[])
- {
- SDL_Init(SDL_INIT_VIDEO);
- displayWindow = SDL_CreateWindow("Noman Hamlani - Assignement 2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 360, SDL_WINDOW_OPENGL);
- SDL_GLContext context = SDL_GL_CreateContext(displayWindow);
- SDL_GL_MakeCurrent(displayWindow, context);
- #ifdef _WINDOWS
- glewInit();
- #endif
- // setup
- glViewport(0, 0, 640, 360);
- ShaderProgram program(RESOURCE_FOLDER"vertex_textured.glsl", RESOURCE_FOLDER"fragment_textured.glsl");
- Matrix projection_matrix;
- Matrix model_matrix;
- Matrix view_matrix;
- projection_matrix.setOrthoProjection(-3.55f, 3.55f, -2.0f, 2.0f, -1.0f, 1.0f);
- SDL_Event event;
- bool done = false;
- while (!done) {
- while (SDL_PollEvent(&event)) {
- if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
- done = true;
- }
- }
- program.setModelMatrix(model_matrix);
- program.setProjectionMatrix(projection_matrix);
- program.setViewMatrix(view_matrix);
- glClear(GL_COLOR_BUFFER_BIT);
- glUseProgram(program.programID);
- 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 };
- glVertexAttribPointer(program.positionAttribute, 2, GL_FLOAT, false, 0, shipVertices);
- glEnableVertexAttribArray(program.positionAttribute);
- glDrawArrays(GL_TRIANGLES, 0, 6);
- glDisableVertexAttribArray(program.positionAttribute);
- SDL_GL_SwapWindow(displayWindow);
- }
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement