Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include "glad/glad.h"
  2. #include <GLFW/glfw3.h>
  3. #define STB_IMAGE_IMPLEMENTATION
  4. #include "glm/glm.hpp"
  5. #include "glm/gtc/matrix_transform.hpp"
  6. #include "glm/gtc/type_ptr.hpp"
  7.  
  8. #include <iostream>
  9. #include "window.h"
  10. #include "shader.h"
  11. #include "buffer.h"
  12. #include "array.h"
  13. #include "vector2.h"
  14. #include "image.h"
  15.  
  16. using namespace MyEngine;
  17.  
  18. void processInput(GLFWwindow* window,float opacity) {
  19.  
  20. }
  21.  
  22. int main() {
  23.     Window window;
  24.     window.create("Hello, Triangle!", 700, 700);
  25.     Shader shader("../shaders/shader.vs", "../shaders/shader.fs");
  26.     shader.use();
  27.  
  28.     float vertices[] {
  29.         -0.5f, 0.5f, 0.0f, 0.0f, 0.0f,
  30.         -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
  31.         0.5f, -0.5f, 0.0f,  1.0f, 1.0f,                    
  32.         0.5f, 0.5f, 0.0f, 1.0f, 0.0f
  33.     };
  34.  
  35.     unsigned int indices[] {
  36.         0, 1, 3,
  37.         1, 2, 3
  38.     };
  39.  
  40.     TextureCache cache;
  41.     glActiveTexture(GL_TEXTURE0);
  42.     Texture anime(cache.getTexture("../Textures/anime.jpg"));
  43.    
  44.     glActiveTexture(GL_TEXTURE1);
  45.     Texture wall(cache.getTexture("../Textures/wall.jpg"));
  46.  
  47.     VertexArray VAO;
  48.     VAO.bind();
  49.  
  50.     Buffer VBO;
  51.     VBO.load(vertices, GL_STATIC_DRAW);
  52.  
  53.     ElementBuffer EBO;
  54.     EBO.load(indices, GL_STATIC_DRAW);
  55.  
  56.     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
  57.     glEnableVertexAttribArray(0);
  58.  
  59.     glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3*sizeof(float)));
  60.     glEnableVertexAttribArray(1);
  61.  
  62.  
  63.     shader.setInt("ourTexture1", 0);
  64.     shader.setInt("ourTexture2", 1);
  65.  
  66.     shader.setFloat("kek", 0.5f);
  67.     float kek = 0.5f;
  68.  
  69.     glm::mat4 trans;
  70.     trans = glm::rotate(trans, glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
  71.     trans = glm::scale(trans, glm::vec3(0.5f, 0.5f, 0.5f));
  72.  
  73.     unsigned int transformLoc = glGetUniformLocation(shader.getID(), "transform");
  74.     glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(trans));
  75.     shader.use();
  76.  
  77.     while(window.isOpen()) {
  78.         window.clear();
  79.  
  80.         glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  81.  
  82.         if(glfwGetKey(window.getWindowPointer(), GLFW_KEY_UP) == GLFW_PRESS && kek < 1.0) {
  83.             kek += 0.01;
  84.         }
  85.         if(glfwGetKey(window.getWindowPointer(), GLFW_KEY_DOWN) == GLFW_PRESS && kek > 0.0) {
  86.             kek -= 0.01;
  87.         }
  88.  
  89.         shader.setFloat("kek", kek);
  90.         window.pollEvents();
  91.         window.swapBuffers();
  92.     }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement