-
-
Save iKlsR/3239625 to your computer and use it in GitHub Desktop.
front page..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <glm/glm.hpp> | |
#include <glm/gtc/matrix_transform.hpp> | |
#include <glm/gtc/type_ptr.hpp> | |
#include <GL/glew.h> | |
#include <GL/glfw.h> | |
#include "obp/events.hpp" | |
#include "obp/common.hpp" | |
#include "obp/meshdt.hpp" | |
#include "obp/buffer.hpp" | |
#include "obp/loader.hpp" | |
#include "obp/contio.hpp" | |
bool running = true; | |
#define obp_window_title "obp" | |
const GLchar * vertex_shader = { | |
"#version 400\n"\ | |
"in vec3 in_Color;\n" | |
"in vec2 in_Uvs;\n" | |
"in vec3 in_Position;\n" | |
"out vec3 color;\n" | |
"out vec2 uvs;\n" | |
"uniform mat4 projection;\n" | |
"uniform mat4 view;\n" | |
"uniform mat4 model;\n" | |
"mat4 ModelViewProjection;\n" | |
"void main() {\n" | |
" ModelViewProjection = projection * view * model;\n" | |
" gl_Position = ModelViewProjection * vec4(in_Position, 1.0);\n" | |
" color = in_Color;\n" | |
" uvs = in_Uvs;\n" | |
"}\n" | |
}; | |
const GLchar * grid_frag_shader = { | |
"#version 400\n" | |
"in vec3 color;\n" | |
"out vec4 out_Color;\n" | |
"void main() {\n" | |
" out_Color = vec4(color, 1.0);\n" | |
"}\n" | |
}; | |
const GLchar * cube_frag_shader = { | |
"#version 400\n" | |
"in vec3 color;\n" | |
"in vec2 uvs;\n" | |
"out vec4 out_Color;\n" | |
"uniform sampler2D texture;\n" | |
"void main() {\n" | |
" out_Color = texture2D(texture, uvs);\n" | |
"}\n" | |
}; | |
int main (int argc, char * argvs[]) { | |
glfwInit(); | |
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); | |
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); | |
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0); | |
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); | |
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); | |
obp_window_handle = glfwOpenWindow(obp_window_width, obp_window_height, 0, 0, 0, 0, 32, 0, GLFW_WINDOW); | |
glfwSetWindowTitle(obp_window_title); | |
obp_gl_info(); //no console | |
obp_callbacks(true, true); | |
GLenum glewInitResult = glewInit(); | |
glfwEnable(GLFW_STICKY_KEYS); | |
glfwEnable(GLFW_STICKY_MOUSE_BUTTONS); | |
glEnable(GL_DEPTH_TEST); | |
{ | |
glfwSetMousePos(obp_window_width /2, obp_window_height /2); | |
glfwDisable(GLFW_MOUSE_CURSOR); | |
} | |
GLint posAttrib, colAttrib, uvAttrib, norAttrib, posAttrib2, colAttrib2, uvAttrib2; | |
GLuint programId, vboId, vboId2, eboId, vaoId, vaoId2, programId2; | |
{ | |
programId = obp_load_shaders_fm(vertex_shader, grid_frag_shader); | |
glBindFragDataLocation(programId, 0, "out_Color"); | |
posAttrib = glGetAttribLocation(programId, "in_Position"); | |
colAttrib = glGetAttribLocation(programId, "in_Color"); | |
glUseProgram(programId); | |
programId2 = obp_load_shaders_fm(vertex_shader, cube_frag_shader); | |
glBindFragDataLocation(programId2, 1, "out_Color"); | |
posAttrib2 = glGetAttribLocation(programId2, "in_Position"); | |
colAttrib2 = glGetAttribLocation(programId2, "in_Color"); | |
uvAttrib2 = glGetAttribLocation(programId2, "in_Uvs"); | |
/*______________________________________________________________________________________________________________________________*/ | |
obp_resources.vertex_array[0] = obp_make_vao(); | |
obp_resources.vertex_buffer[0] = obp_make_buffer(GL_ARRAY_BUFFER, sizeof(obp_grid_vertices), obp_grid_vertices); | |
glEnableVertexAttribArray(posAttrib); | |
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid *)0); | |
glEnableVertexAttribArray(colAttrib); | |
glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid *)(3 * sizeof(GLfloat))); | |
/*______________________________________________________________________________________________________________________________*/ | |
obp_resources.vertex_array[1] = obp_make_vao(); | |
obp_resources.vertex_buffer[1] = obp_make_buffer(GL_ARRAY_BUFFER, sizeof(obp_cube_vertices), obp_cube_vertices); | |
obp_resources.element_buffer[0] = obp_make_buffer(GL_ELEMENT_ARRAY_BUFFER, sizeof(obp_cube_elements), obp_cube_elements); | |
glEnableVertexAttribArray(posAttrib2); | |
glVertexAttribPointer(posAttrib2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)0); | |
glEnableVertexAttribArray(colAttrib2); | |
glVertexAttribPointer(colAttrib2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)(3 * sizeof(GLfloat))); | |
glEnableVertexAttribArray(uvAttrib2); | |
glVertexAttribPointer(uvAttrib2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)(6 * sizeof(GLfloat))); | |
obp_resources.texture[0] = obp_load_image("tex\\tle\\crate.png", GL_TEXTURE0); | |
glUniform1i(glGetUniformLocation(programId2, "texture"), 0); | |
} | |
glClearColor(0.1f, 0.1, 0.1f, 1.0f); | |
while (running) { | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
{ | |
obp_camera(2); | |
GLint uniProjection, uniView, uniModel; | |
glm::mat4 projection, view, model; | |
uniProjection = glGetUniformLocation(programId, "projection"); | |
uniView = glGetUniformLocation(programId, "view"); | |
uniModel = glGetUniformLocation(programId, "model"); | |
projection = getProjectionMatrix(); | |
view = getViewMatrix(); | |
model = glm::mat4(1.0f); | |
glUniformMatrix4fv(uniProjection, 1, GL_FALSE, glm::value_ptr(projection)); | |
glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view)); | |
glUniformMatrix4fv(uniModel, 1, GL_FALSE, glm::value_ptr(model)); | |
} | |
{ | |
obp_bind_vao(obp_resources.vertex_array[0]); | |
glDrawArrays(GL_LINES, 0, 44); | |
glUseProgram(programId2); | |
obp_bind_vao(obp_resources.vertex_array[1]); | |
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); | |
} | |
glfwSwapBuffers(); | |
} | |
{ | |
} | |
glfwTerminate(); | |
return OBP_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment