Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable : 4996)
- #pragma warning(suppress : 4996)
- #include <iostream>
- #include <stdio.h>
- #include <GL/glew.h>
- #include <SFML/Window.hpp>
- #include <SFML/System/Time.hpp>
- #include <glm/glm.hpp>
- #include <glm/gtc/matrix_transform.hpp>
- #include <glm/gtc/type_ptr.hpp>
- #define STB_IMAGE_IMPLEMENTATION
- #include "stb_image.h"
- // Kody shaderów
- const GLchar* vertexSource = R"glsl(
- #version 150 core
- in vec3 position;
- in vec3 color;
- in vec3 aNormal;
- out vec3 Normal;
- out vec3 FragPos;
- uniform mat4 model;
- uniform mat4 view;
- uniform mat4 proj;
- out vec3 Color;
- in vec2 aTexCoord;
- out vec2 TexCoord;
- void main(){
- Color = color;
- gl_Position = proj * view * model * vec4(position, 1.0);
- TexCoord = aTexCoord;
- }
- )glsl";
- const GLchar* fragmentSource = R"glsl(
- #version 150 core
- in vec3 Color;
- out vec4 outColor;
- in vec2 TexCoord;
- in vec3 Normal;
- in vec3 FragPos;
- in vec3 lightPos;
- uniform sampler2D texture1;
- void main()
- {
- float ambientStrength = 0.4; // ambient
- vec3 ambientlightColor = vec3(0.8,0.8,0.8);
- vec4 ambient = ambientStrength * vec4(ambientlightColor,0.7);
- vec3 difflightColor = vec3(0.8,0.8,0.8);
- vec3 norm = normalize(Normal);
- vec3 lightDir = normalize(lightPos - FragPos);
- float diff = max(dot(norm, lightDir), 0.0);
- vec3 diffuse = diff * difflightColor;
- //outColor = vec4(Color, 1.0);
- //outColor=texture(texture1, TexCoord);
- outColor = (ambient+vec4(diffuse,0.3)) * texture(texture1, TexCoord);
- }
- )glsl";
- //ZMIENNE OPISUJĄCE KAMERE
- glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.0f);
- glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, -1.0f);
- glm::vec3 cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
- float obrot = 0;
- //
- bool loadOBJ(
- const char* path,
- std::vector < glm::vec3 >& out_vertices,
- std::vector < glm::vec2 >& out_uvs,
- std::vector < glm::vec3 >& out_normals
- )
- {
- std::vector< unsigned int > vertexIndices, uvIndices, normalIndices;
- std::vector< glm::vec3 > temp_vertices;
- std::vector< glm::vec2 > temp_uvs;
- std::vector< glm::vec3 > temp_normals;
- FILE* file = fopen("D:\\GrafikaKomputerowa\\GKPomocOlka\\Grass_block.obj","r");
- if (file == NULL) {
- printf("Impossible to open the file !\n");
- return false;
- }
- while (1) {
- char lineHeader[128];
- // read the first word of the line
- int res = fscanf(file, "%s", lineHeader);
- if (res == EOF)
- break; // EOF = End Of File. Quit the loop.
- // else : parse lineHeader
- if (strcmp(lineHeader, "v") == 0) {
- glm::vec3 vertex;
- fscanf(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z);
- temp_vertices.push_back(vertex);
- }
- else if (strcmp(lineHeader, "vt") == 0) {
- glm::vec2 uv;
- fscanf(file, "%f %f\n", &uv.x, &uv.y);
- temp_uvs.push_back(uv);
- }
- else if (strcmp(lineHeader, "vn") == 0) {
- glm::vec3 normal;
- fscanf(file, "%f %f %f\n", &normal.x, &normal.y, &normal.z);
- temp_normals.push_back(normal);
- }
- else if (strcmp(lineHeader, "f") == 0) {
- std::string vertex1, vertex2, vertex3;
- unsigned int vertexIndex[3], uvIndex[3], normalIndex[3];
- int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2]);
- if (matches != 9) {
- printf("File can't be read by our simple parser : ( Try exporting with other options\n");
- return false;
- }
- vertexIndices.push_back(vertexIndex[0]);
- vertexIndices.push_back(vertexIndex[1]);
- vertexIndices.push_back(vertexIndex[2]);
- uvIndices.push_back(uvIndex[0]);
- uvIndices.push_back(uvIndex[1]);
- uvIndices.push_back(uvIndex[2]);
- normalIndices.push_back(normalIndex[0]);
- normalIndices.push_back(normalIndex[1]);
- normalIndices.push_back(normalIndex[2]);
- }
- // For each vertex of each triangle
- for (unsigned int i = 0; i < vertexIndices.size(); i++) {
- unsigned int vertexIndex = vertexIndices[i];
- glm::vec3 vertex = temp_vertices[vertexIndex - 1];
- out_vertices.push_back(vertex);
- }
- }
- }
- bool firstMouse = true;
- //
- glm::vec3 ustawKamereMysz(sf::Window* window, GLfloat xpos, GLfloat ypos)
- {
- GLfloat lastX;
- GLfloat lastY;
- if (firstMouse) // initially set to true
- {
- lastX = xpos;
- lastY = ypos;
- firstMouse = false;
- }
- sf::Vector2i localPosition = sf::Mouse::getPosition();
- lastX = localPosition.x;
- lastY = localPosition.y;
- GLfloat xoffset = xpos - lastX;
- GLfloat yoffset = lastY - ypos;
- //sf::Vector2i localPosition = sf::Mouse::getPosition();
- //lastX = localPosition.x;
- //lastY = localPosition.y;
- GLdouble yaw = -90; //obrót względem osi Y
- GLdouble pitch = 0; //obrót względem osi X
- GLfloat sensitivity = 0.1f;
- xoffset *= sensitivity;
- yoffset *= sensitivity;
- yaw += xoffset;
- pitch += yoffset;
- if (pitch > 89.0f)
- pitch = 89.0f;
- if (pitch < -89.0f)
- pitch = -89.0f;
- glm::vec3 direction;
- direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
- direction.y = sin(glm::radians(pitch));
- direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
- return direction;
- }
- //
- //ZAJ4
- unsigned int texture1;
- int main()
- {
- sf::ContextSettings settings;
- settings.depthBits = 24;
- settings.stencilBits = 8;
- // Okno renderingu
- sf::Window window(sf::VideoMode(800, 600, 32), "OpenGL", sf::Style::Titlebar | sf::Style::Close, settings);
- window.setMouseCursorGrabbed(true); //przechwycenie kursora myszy w oknie ------------
- window.setMouseCursorVisible(false); //ukrycie kursora myszy ---------------------
- window.setFramerateLimit(20);
- // Inicjalizacja GLEW
- glewExperimental = GL_TRUE;
- glewInit();
- // Utworzenie VAO (Vertex Array Object)
- GLuint vao;
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
- // Utworzenie VBO (Vertex Buffer Object)
- // i skopiowanie do niego danych wierzchołkowych
- GLuint vbo;
- glGenBuffers(1, &vbo);
- glGenTextures(1, &texture1); // Generuje tekstury
- glBindTexture(GL_TEXTURE_2D, texture1); //Ustawienie tekstury jako bieżącej (powiązanie)
- // set the texture wrapping parameters
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- // set texture wrapping to GL_REPEAT (default wrapping method)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- // set texture filtering parameters
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // load image, create texture and generate mipmaps
- int width, height, nrChannels;
- stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
- unsigned char* data = stbi_load("D:\\GrafikaKomputerowa\\GKPomocOlka\\Java.png", &width, &height, &nrChannels, 0);
- if (data)
- {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
- glGenerateMipmap(GL_TEXTURE_2D);
- }
- else
- {
- std::cout << "Failed to load texture" << std::endl;
- }
- stbi_image_free(data);
- /*
- ///Zmiana 2) - odwrócony trójkąt
- GLfloat* vertices = new GLfloat[]{
- -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,// Top-left
- 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,// Top-right
- 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, // Bottom-right
- 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,// Bottom-right
- -0.5f, -0.5f, 1.0f, 1.0f, 1.0f,// Bottom-left
- -0.5f, 0.5f, 1.0f, 0.0f, 0.0f // Top-left
- };
- */
- /*
- float v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.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,1.0f,
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f,1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f,0.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f,0.0f,
- 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f,0.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,1.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 1.0f,1.0f,
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f,1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f,0.0f
- };
- */
- // Read our .obj file
- std::vector< glm::vec3 > vertices;
- std::vector< glm::vec2 > uvs;
- std::vector< glm::vec3 > normals; // Won't be used at the moment.
- bool res = loadOBJ("Grass_block.obj", vertices, uvs, normals);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
- // Utworzenie i skompilowanie shadera wierzchołków
- GLuint vertexShader =
- glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(vertexShader, 1, &vertexSource, NULL);
- glCompileShader(vertexShader);
- // Utworzenie i skompilowanie shadera fragmentów
- GLuint fragmentShader =
- glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
- glCompileShader(fragmentShader);
- // Zlinkowanie obu shaderów w jeden wspólny program
- GLuint shaderProgram = glCreateProgram();
- glAttachShader(shaderProgram, vertexShader);
- glAttachShader(shaderProgram, fragmentShader);
- glBindFragDataLocation(shaderProgram, 0, "outColor");
- glLinkProgram(shaderProgram);
- glUseProgram(shaderProgram);
- ///
- glm::vec3 lightPos(1.2f, 1.0f, 2.0f);
- GLint uniLightPos = glGetUniformLocation(shaderProgram, "lightPos");
- glUniform3fv(uniLightPos, 1, &lightPos[0]);
- //
- // Specifikacja formatu danych wierzchołkowych
- GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
- glEnableVertexAttribArray(posAttrib);
- glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0);
- GLint colAttrib = glGetAttribLocation(shaderProgram, "color");
- glEnableVertexAttribArray(colAttrib);
- ///
- GLint NorAttrib = glGetAttribLocation(shaderProgram, "aNormal");
- glEnableVertexAttribArray(NorAttrib);
- glVertexAttribPointer(
- NorAttrib, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(3 * sizeof(GLfloat)));
- //3)Zepsuje tutaj w tym miejscu ostatni parametr i program zamiast się wysypać zmieni kolor figury w środku
- glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
- // Rozpoczęcie pętli zdarzeń
- bool running = true;
- //ZMIANY
- int punkty_ = 6;
- long prymityw = GL_TRIANGLES;
- GLfloat mouse_y = 500;
- GLfloat mouse_x = 600;
- //ZMIANY
- //
- GLint vStatus;
- glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &vStatus);
- std::cout << "Vertex shader: ";
- if (vStatus == GL_TRUE) {
- std::cout << "OK" << std::endl;
- }
- else {
- std::cout << "EROOR" << std::endl;
- char vBuffer[128];
- glGetShaderInfoLog(vertexShader, 64, NULL, vBuffer);
- std::cout << vBuffer << std::endl;
- }
- //
- //
- glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &vStatus);
- std::cout << "Fragment shader: ";
- if (vStatus == GL_TRUE) {
- std::cout << "OK" << std::endl;
- }
- else {
- std::cout << "EROOR" << std::endl;
- char vBuffer[128];
- glGetShaderInfoLog(fragmentShader, 64, NULL, vBuffer);
- std::cout << vBuffer << std::endl;
- }
- //
- glm::mat4 model = glm::mat4(1.0f);
- model = glm::rotate(model, glm::radians(45.0f), glm::vec3(0.0f, 0.0f, 1.0f));
- GLint uniTrans = glGetUniformLocation(shaderProgram, "model");
- glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(model));
- glm::mat4 view;
- view = glm::lookAt(glm::vec3(0.0f, 0.0f, 3.0f),
- glm::vec3(0.0f, 0.0f, 0.0f),
- glm::vec3(0.0f, 1.0f, 0.0f));
- GLint uniView = glGetUniformLocation(shaderProgram, "view");
- glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
- glm::mat4 proj = glm::perspective(glm::radians(45.0f), 800.0f / 800.0f, 0.06f, 100.0f);
- GLint uniProj = glGetUniformLocation(shaderProgram, "proj");
- glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(proj));
- view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
- float cameraSpeed = 0.1f;
- float obrot = 0.3f;
- sf::Clock clock;
- sf::Time time;
- while (running) {
- sf::Event windowEvent;
- time = clock.getElapsedTime();
- clock.restart();
- float cameraSpeed = 0.02f * time.asMicroseconds();
- while (window.pollEvent(windowEvent)) {
- switch (windowEvent.type) {
- case sf::Event::Closed:
- running = false;
- break;
- case sf::Event::KeyPressed:
- {
- switch (windowEvent.key.code)
- {
- case sf::Keyboard::Num1:
- prymityw = GL_POINTS;
- break;
- case sf::Keyboard::Num2:
- prymityw = GL_LINES;
- break;
- case sf::Keyboard::Num3:
- prymityw = GL_LINE_STRIP;
- break;
- case sf::Keyboard::Num4:
- prymityw = GL_LINE_LOOP;
- break;
- case sf::Keyboard::Num5:
- prymityw = GL_TRIANGLES;
- break;
- case sf::Keyboard::Num6:
- prymityw = GL_TRIANGLE_STRIP;
- break;
- case sf::Keyboard::Num7:
- prymityw = GL_TRIANGLE_FAN;
- break;
- case sf::Keyboard::Num8:
- prymityw = GL_QUADS;
- break;
- case sf::Keyboard::Num9:
- prymityw = GL_QUAD_STRIP;
- break;
- case sf::Keyboard::Num0:
- prymityw = GL_POLYGON;
- break;
- case sf::Keyboard::Left:
- cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
- view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
- glGetUniformLocation(shaderProgram, "view");
- glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
- break;
- case sf::Keyboard::Right:
- cameraPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
- view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
- glGetUniformLocation(shaderProgram, "view");
- glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
- break;
- case sf::Keyboard::Up:
- cameraPos -= cameraSpeed * cameraUp;
- view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
- glGetUniformLocation(shaderProgram, "view");
- glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
- break;
- case sf::Keyboard::Down:
- cameraPos += cameraSpeed * cameraUp;
- view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
- glGetUniformLocation(shaderProgram, "view");
- glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
- break;
- case sf::Keyboard::R:
- model = glm::rotate(model, glm::radians(30.0f) + obrot, glm::vec3(0.0f, 0.0f, 1.0f));
- glGetUniformLocation(shaderProgram, "model");
- glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(model));
- break;
- case sf::Keyboard::Escape:
- window.close();
- return 0;
- break;
- }
- case sf::Event::MouseMoved:
- glm::vec3 direction;
- direction = ustawKamereMysz(&window, mouse_x, mouse_y);
- cameraFront = glm::normalize(direction);
- view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
- glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view));
- break;
- }
- }
- // Nadanie scenie koloru czarnego
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- // Narysowanie trójkąta na podstawie 3 wierzchołków
- ///Zmiana 2.1 z 3 wierzchołków na 6 wierzchołków
- ///
- //glBindBuffer(GL_ARRAY_BUFFER, buffer);
- GLint TexCoord = glGetAttribLocation(shaderProgram, "aTexCoord");
- glEnableVertexAttribArray(TexCoord);
- glVertexAttribPointer(TexCoord, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(6 *
- sizeof(GLfloat)));
- glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
- glBindTexture(GL_TEXTURE_2D, texture1);
- glDrawArrays(prymityw, 0, punkty_);
- // Wymiana buforów tylni/przedni
- window.display();
- }
- }
- // Kasowanie programu i czyszczenie buforów
- glDeleteProgram(shaderProgram);
- glDeleteShader(fragmentShader);
- glDeleteShader(vertexShader);
- glDeleteBuffers(1, &vbo);
- glDeleteVertexArrays(1, &vao);
- // Zamknięcie okna renderingu
- window.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement