damit john
This commit is contained in:
parent
f2c45b45cd
commit
58a9a8cbf9
|
@ -14,6 +14,8 @@
|
|||
"move.h": "c",
|
||||
"hash.h": "c",
|
||||
"proj.h": "c",
|
||||
"entities.h": "c"
|
||||
"entities.h": "c",
|
||||
"menus.h": "c",
|
||||
"structure.h": "c"
|
||||
}
|
||||
}
|
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/menus.o
BIN
obj/menus.o
Binary file not shown.
|
@ -174,12 +174,4 @@ void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsi
|
|||
glm_lookat((vec3){(float)camx, (float)camy, (float)camz}, direction, (vec3){0.0f, 1.0f, 0.0f}, view);
|
||||
|
||||
glm_perspective(glm_rad((float)fov), 1500.0f / 1000.0f, 0.1f, 100.0f, projection);
|
||||
|
||||
glUseProgram(shaderProgram);
|
||||
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
|
||||
}
|
||||
|
||||
void gl_drawTriangle() {
|
||||
|
||||
}
|
145
src/main.c
145
src/main.c
|
@ -15,6 +15,7 @@
|
|||
#include "structure.h"
|
||||
#include "base.h"
|
||||
#include "move.h"
|
||||
#include "menus.h"
|
||||
#include "proj.h"
|
||||
#include "entities.h"
|
||||
#include "display.h"
|
||||
|
@ -112,6 +113,21 @@ const char *fragmentShaderSource = "#version 330 core\n"
|
|||
" FragColor = u_color;\n"
|
||||
"}\0";
|
||||
|
||||
const char *vertexShaderSourceR = "#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"uniform mat4 scale;\n"
|
||||
"uniform mat4 slide;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = slide * scale * vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||
"}\0";
|
||||
|
||||
const char *fragmentShaderSourceR = "#version 330 core\n"
|
||||
"uniform vec4 u_color2;\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"void main() {\n"
|
||||
" FragColor = u_color2;\n"
|
||||
"}\0";
|
||||
|
||||
int main_alt() {
|
||||
// glfw: initialize and configure
|
||||
// ------------------------------
|
||||
|
@ -144,7 +160,14 @@ int main_alt() {
|
|||
glCullFace(GL_FRONT);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
//printf("%f\n", glDepthRange);
|
||||
init_csts();
|
||||
init_hashtbl();
|
||||
init_ent_generator(10);
|
||||
init_proj();
|
||||
parse_rooms(5);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||
|
||||
// build and compile our shader program
|
||||
// ------------------------------------
|
||||
|
@ -161,6 +184,7 @@ int main_alt() {
|
|||
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
|
||||
fprintf(stderr, "ERROR : cannot initialize shader (1)");
|
||||
}
|
||||
|
||||
// fragment shader
|
||||
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
|
||||
|
@ -170,31 +194,98 @@ int main_alt() {
|
|||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
|
||||
fprintf(stderr, "ERROR : cannot initialize shader (2)");
|
||||
fprintf(stderr, "ERROR : cannot initialize shader (3)");
|
||||
}
|
||||
|
||||
// link shaders
|
||||
unsigned int shaderProgram = glCreateProgram();
|
||||
glAttachShader(shaderProgram, vertexShader);
|
||||
glAttachShader(shaderProgram, fragmentShader);
|
||||
glLinkProgram(shaderProgram);
|
||||
// check for linking errors
|
||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
|
||||
fprintf(stderr, "ERROR : cannot link shaders");
|
||||
}
|
||||
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
// set up data (buffer(s)) and configure vertex attributes
|
||||
// ------------------------------------------------------------------
|
||||
// main VAO/VBO
|
||||
unsigned int VBO, VAO;
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glGenBuffers(1, &VBO);
|
||||
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
init_csts();
|
||||
init_hashtbl();
|
||||
init_ent_generator(10);
|
||||
init_proj();
|
||||
parse_rooms(5);
|
||||
init_vertices();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||
|
||||
// build and compile our shader program
|
||||
// ------------------------------------
|
||||
// vertex shader
|
||||
unsigned int vertexShaderR = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertexShaderR, 1, &vertexShaderSourceR, NULL);
|
||||
glCompileShader(vertexShaderR);
|
||||
// check for shader compile errors
|
||||
glGetShaderiv(vertexShaderR, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(vertexShaderR, 512, NULL, infoLog);
|
||||
//std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
// fragment shader
|
||||
unsigned int fragmentShaderR = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragmentShaderR, 1, &fragmentShaderSourceR, NULL);
|
||||
glCompileShader(fragmentShaderR);
|
||||
// check for shader compile errors
|
||||
glGetShaderiv(fragmentShaderR, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(fragmentShaderR, 512, NULL, infoLog);
|
||||
//std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
// link shaders
|
||||
unsigned int shaderProgramR = glCreateProgram();
|
||||
glAttachShader(shaderProgramR, vertexShaderR);
|
||||
glAttachShader(shaderProgramR, fragmentShaderR);
|
||||
glLinkProgram(shaderProgramR);
|
||||
// check for linking errors
|
||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(shaderProgramR, 512, NULL, infoLog);
|
||||
//std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
glDeleteShader(vertexShaderR);
|
||||
glDeleteShader(fragmentShaderR);
|
||||
|
||||
// rectangle VAO/VBO
|
||||
initMenus();
|
||||
|
||||
unsigned int RVBO, RVAO;
|
||||
glGenVertexArrays(1, &RVAO);
|
||||
glGenBuffers(1, &RVBO);
|
||||
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
|
||||
glBindVertexArray(RVAO);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, RVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(rectDefault), rectDefault, GL_STATIC_DRAW);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
// note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
// You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO, but this rarely happens. Modifying other
|
||||
// VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary.
|
||||
glBindVertexArray(0);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||
|
||||
int fps = 60 ;
|
||||
int interval = 1000000/fps ;
|
||||
|
@ -202,21 +293,6 @@ int main_alt() {
|
|||
clock_t finish = clock();
|
||||
clock_t origin = clock();
|
||||
|
||||
unsigned int VBO, VAO;
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glGenBuffers(1, &VBO);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
init_vertices();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
|
||||
|
||||
// position attribute
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
// input
|
||||
// -----
|
||||
|
@ -226,13 +302,18 @@ int main_alt() {
|
|||
|
||||
generate_nearby_chunks(1);
|
||||
|
||||
glUseProgram(shaderProgram);
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
|
||||
gl_initRender(shaderProgram, shaderProgram, VAO, VBO);
|
||||
//gl_renderAll(shaderProgram, shaderProgram, VAO, VBO, current_room, 0.0, 0.0, 0.0);
|
||||
gl_renderNearbyChunks(shaderProgram, shaderProgram, VAO, VBO, 1);
|
||||
gl_renderProj(shaderProgram, shaderProgram, VAO, VBO);
|
||||
|
||||
glUseProgram(shaderProgramR);
|
||||
glBindVertexArray(RVAO);
|
||||
|
||||
gl_drawRect(shaderProgramR, RVAO, RVBO, -0.5f, -0.5f, 0.5f, 0.5f, 255, 43, 255);
|
||||
|
||||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||
// -------------------------------------------------------------------------------
|
||||
finish = clock();
|
||||
|
|
33
src/menus.c
33
src/menus.c
|
@ -8,6 +8,10 @@
|
|||
#include <termios.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include <glad/glad.h>
|
||||
#include "../include/glad/glad.h"
|
||||
//#include <GLFW/glfw3.h>
|
||||
#include <cglm/cglm.h>
|
||||
|
||||
#include "hash.h"
|
||||
#include "structure.h"
|
||||
|
@ -15,3 +19,32 @@
|
|||
#include "entities.h"
|
||||
#include "menus.h"
|
||||
|
||||
float rectDefault[18] ;
|
||||
|
||||
static mat4 scale, slide;
|
||||
void initMenus() {
|
||||
rectDefault[0] = -0.5f; rectDefault[1] = -0.5f; rectDefault[2] = -1.0f;
|
||||
rectDefault[3] = -0.5f; rectDefault[4] = 0.5f; rectDefault[5] = -1.0f;
|
||||
rectDefault[6] = 0.5f; rectDefault[7] = 0.5f; rectDefault[8] = -1.0f;
|
||||
|
||||
rectDefault[9] = -0.5f; rectDefault[10] = -0.5f; rectDefault[11] = -1.0f;
|
||||
rectDefault[12] = 0.5f; rectDefault[13] = 0.5f; rectDefault[14] = -1.0f;
|
||||
rectDefault[15] = 0.5f; rectDefault[16] = -0.5f; rectDefault[17] = -1.0f;
|
||||
}
|
||||
|
||||
void gl_drawRect(unsigned int fragShader, unsigned int VAO, unsigned int VBO, float x, float y, float w, float h, int r, int g, int b) {
|
||||
glm_mat4_identity(scale);
|
||||
glm_mat4_identity(slide);
|
||||
|
||||
scale[0][0] = 0.5f;
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(fragShader, "scale"), 1, GL_FALSE, (float*)scale);
|
||||
glUniformMatrix4fv(glGetUniformLocation(fragShader, "slide"), 1, GL_FALSE, (float*)slide);
|
||||
glUniform4f(glGetUniformLocation(fragShader, "u_color2"), 0.9f, 0.4f, 0.6f, 0.5f);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
void gl_initDrawRect(unsigned int shaderProgram) {
|
||||
glUseProgram(shaderProgram);
|
||||
}
|
|
@ -1,5 +1,9 @@
|
|||
#ifndef MENUS_H
|
||||
#define MENUS_H
|
||||
|
||||
void initMenus();
|
||||
|
||||
void gl_drawRect(unsigned int fragShader, unsigned int VAO, unsigned int VBO, float x, float y, float w, float h, int r, int g, int b);
|
||||
void gl_initDrawRect(unsigned int shaderProgram);
|
||||
|
||||
#endif
|
|
@ -122,5 +122,6 @@ extern double min_dist ;
|
|||
// ---------------------------------------------------------------------------------------------------- //
|
||||
|
||||
extern float vertices[108];
|
||||
extern float rectDefault[18];
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue