IM FREEEEEEEEE

This commit is contained in:
Alexandre 2025-01-30 21:45:46 +01:00
parent 5d3504ca53
commit 0cf97eb7b5
16 changed files with 4063 additions and 19 deletions

View File

@ -1,6 +1,6 @@
CC = gcc
FLAGS = -O2 -Wall -Wextra -Wpedantic -g
LFLAGS = -lSDL2 -lSDL2_image -lm -lncurses
FLAGS = -O2 -Wall -Wextra -g
LFLAGS = -lSDL2 -lSDL2_image -lm -lncurses src/glad.c -ldl -lglfw -lcglm
all: bin/back

BIN
bin/back

Binary file not shown.

311
include/KHR/khrplatform.h Normal file
View File

@ -0,0 +1,311 @@
#ifndef __khrplatform_h_
#define __khrplatform_h_
/*
** Copyright (c) 2008-2018 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/* Khronos platform-specific types and definitions.
*
* The master copy of khrplatform.h is maintained in the Khronos EGL
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
* The last semantic modification to khrplatform.h was at commit ID:
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
*
* Adopters may modify this file to suit their platform. Adopters are
* encouraged to submit platform specific modifications to the Khronos
* group so that they can be included in future versions of this file.
* Please submit changes by filing pull requests or issues on
* the EGL Registry repository linked above.
*
*
* See the Implementer's Guidelines for information about where this file
* should be located on your system and for more details of its use:
* http://www.khronos.org/registry/implementers_guide.pdf
*
* This file should be included as
* #include <KHR/khrplatform.h>
* by Khronos client API header files that use its types and defines.
*
* The types in khrplatform.h should only be used to define API-specific types.
*
* Types defined in khrplatform.h:
* khronos_int8_t signed 8 bit
* khronos_uint8_t unsigned 8 bit
* khronos_int16_t signed 16 bit
* khronos_uint16_t unsigned 16 bit
* khronos_int32_t signed 32 bit
* khronos_uint32_t unsigned 32 bit
* khronos_int64_t signed 64 bit
* khronos_uint64_t unsigned 64 bit
* khronos_intptr_t signed same number of bits as a pointer
* khronos_uintptr_t unsigned same number of bits as a pointer
* khronos_ssize_t signed size
* khronos_usize_t unsigned size
* khronos_float_t signed 32 bit floating point
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for
* booleans cannot use this as the base type for their boolean.
*
* Tokens defined in khrplatform.h:
*
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
*
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
*
* Calling convention macros defined in this file:
* KHRONOS_APICALL
* KHRONOS_APIENTRY
* KHRONOS_APIATTRIBUTES
*
* These may be used in function prototypes as:
*
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
* int arg1,
* int arg2) KHRONOS_APIATTRIBUTES;
*/
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
# define KHRONOS_STATIC 1
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APICALL
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
#if defined(KHRONOS_STATIC)
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
* header compatible with static linking. */
# define KHRONOS_APICALL
#elif defined(_WIN32)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
#elif defined(__ANDROID__)
# define KHRONOS_APICALL __attribute__((visibility("default")))
#else
# define KHRONOS_APICALL
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIENTRY
*-------------------------------------------------------------------------
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else
# define KHRONOS_APIENTRY
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIATTRIBUTES
*-------------------------------------------------------------------------
* This follows the closing parenthesis of the function prototype arguments.
*/
#if defined (__ARMCC_2__)
#define KHRONOS_APIATTRIBUTES __softfp
#else
#define KHRONOS_APIATTRIBUTES
#endif
/*-------------------------------------------------------------------------
* basic type definitions
*-----------------------------------------------------------------------*/
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
/*
* Using <stdint.h>
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
/*
* To support platform where unsigned long cannot be used interchangeably with
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
* unsigned long long or similar (this results in different C++ name mangling).
* To avoid changes for existing platforms, we restrict usage of intptr_t to
* platforms where the size of a pointer is larger than the size of long.
*/
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
#define KHRONOS_USE_INTPTR_T
#endif
#endif
#elif defined(__VMS ) || defined(__sgi)
/*
* Using <inttypes.h>
*/
#include <inttypes.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
/*
* Win32
*/
typedef __int32 khronos_int32_t;
typedef unsigned __int32 khronos_uint32_t;
typedef __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__sun__) || defined(__digital__)
/*
* Sun or Digital
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#if defined(__arch64__) || defined(_LP64)
typedef long int khronos_int64_t;
typedef unsigned long int khronos_uint64_t;
#else
typedef long long int khronos_int64_t;
typedef unsigned long long int khronos_uint64_t;
#endif /* __arch64__ */
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif 0
/*
* Hypothetical platform with no float or int64 support
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#define KHRONOS_SUPPORT_INT64 0
#define KHRONOS_SUPPORT_FLOAT 0
#else
/*
* Generic fallback
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#endif
/*
* Types that are (so far) the same on all platforms
*/
typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t;
/*
* Types that differ between LLP64 and LP64 architectures - in LLP64,
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
* to be the only LLP64 architecture in current use.
*/
#ifdef KHRONOS_USE_INTPTR_T
typedef intptr_t khronos_intptr_t;
typedef uintptr_t khronos_uintptr_t;
#elif defined(_WIN64)
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
#else
typedef signed long int khronos_intptr_t;
typedef unsigned long int khronos_uintptr_t;
#endif
#if defined(_WIN64)
typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t;
#else
typedef signed long int khronos_ssize_t;
typedef unsigned long int khronos_usize_t;
#endif
#if KHRONOS_SUPPORT_FLOAT
/*
* Float type
*/
typedef float khronos_float_t;
#endif
#if KHRONOS_SUPPORT_INT64
/* Time types
*
* These types can be used to represent a time interval in nanoseconds or
* an absolute Unadjusted System Time. Unadjusted System Time is the number
* of nanoseconds since some arbitrary system event (e.g. since the last
* time the system booted). The Unadjusted System Time is an unsigned
* 64 bit value that wraps back to 0 every 584 years. Time intervals
* may be either signed or unsigned.
*/
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t;
#endif
/*
* Dummy value used to pad enum types to 32 bits.
*/
#ifndef KHRONOS_MAX_ENUM
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
#endif
/*
* Enumerated boolean type
*
* Values other than zero should be considered to be true. Therefore
* comparisons should not be made against KHRONOS_TRUE.
*/
typedef enum {
KHRONOS_FALSE = 0,
KHRONOS_TRUE = 1,
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
} khronos_boolean_enum_t;
#endif /* __khrplatform_h_ */

2129
include/glad/glad.h Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -10,6 +10,9 @@
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <cglm/cglm.h>
#include "hash.h"
#include "structure.h"
@ -252,6 +255,12 @@ void rotate_cube(double x0, double y0, double z0, double* rx, double* ry, double
*rz = (cb->z + cb->d/2) + zry*cos(cb->vt_angle) + yry*sin(cb->vt_angle) ;
}
pt_2d pt_rotate_cube_3d(double x0, double y0, double z0, cube_0* cb) {
pt_2d res;
rotate_cube(x0, y0, z0, &(res.x), &(res.y), &(res.z), cb);
return res;
}
void draw_segment(SDL_Renderer* renderer, double sx, double sy, double sz, double ex, double ey, double ez) {
double spx ;double spy ;double spz ;double epx ;double epy ;double epz ;
project_to_camera(sx, sy, sz, &spx, &spy, &spz) ;
@ -455,8 +464,6 @@ void renderTriangleNoProject(
assert(SDL_RenderGeometry(renderer, NULL, vtxs, 3, NULL, 0) == 0);
}
double near = -1.0 ;
double far = 1.0 ;
double getZbuffer(double x, double y, double z) {
return sqrt(x*x + y*y + z*z);
//return z;
@ -869,4 +876,215 @@ void drawData(SDL_Renderer* renderer) {
drawNumberToRenderer(renderer, digits, player_chx, 310, 10, 75/2, 105/2, 0);
drawNumberToRenderer(renderer, digits, player_chy, 310, 60, 75/2, 105/2, 0);
}
float vertices[9] ;
void gl_renderTriangle(unsigned int shaderProgram, unsigned int VAO, unsigned int VBO, double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, float r, float g, float b) {
vertices[0] = (float)x0;
vertices[1] = (float)y0;
vertices[2] = (float)z0;
vertices[3] = (float)x1;
vertices[4] = (float)y1;
vertices[5] = (float)z1;
vertices[6] = (float)x2;
vertices[7] = (float)y2;
vertices[8] = (float)z2;
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);
// 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);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
double near = 0.4 ;
double far = 30.0 ;
double top = 1.0 ;
double bottom = -1.0 ;
double left = -1.0 ;
double right = 1.0 ;
double z_depth(double z) {
return ((2.0*(1/z - 1/near)/(1/far - 1/near)) - 1.0);
//return ((1/z - 1/near)/(1/far - 1/near));
//return (2*z -1);
}
pt_2d gl_project(pt_2d p) {
double w = -p.z;
pt_2d res = {
.x = p.x*(2.0*near/(right-left)) + p.z*(right+left)/(right-left),
.y = p.y*(2.0*near/(top-bottom)) + p.z*(top+bottom)/(top-bottom),
.z = -p.z*(far+near)/(far-near) -(2*far*near)/(far-near),
};
res.x = res.x / w;
res.y = res.y / w;
res.z = res.z / w;
return res;
}
/*
float vertices[] = {
// Positions
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, -0.5f
};*/
void gl_renderSurface(unsigned int shaderProgram, unsigned int VAO, unsigned int VBO, cube_0* c, int sf) {
float vertices[] = {
(float)(c->x), (float)(c->y) , (float)(c->z),
(float)(c->x), (float)(c->y + c->h), (float)(c->z),
(float)(c->x), (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x), (float)(c->y) , (float)(c->z),
(float)(c->x), (float)(c->y) , (float)(c->z + c->d),
(float)(c->x), (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y) , (float)(c->z),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y) , (float)(c->z),
(float)(c->x + c->w), (float)(c->y) , (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x) , (float)(c->y), (float)(c->z),
(float)(c->x + c->w), (float)(c->y), (float)(c->z),
(float)(c->x + c->w), (float)(c->y), (float)(c->z + c->d),
(float)(c->x) , (float)(c->y), (float)(c->z),
(float)(c->x) , (float)(c->y), (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y), (float)(c->z + c->d),
(float)(c->x) , (float)(c->y + c->h), (float)(c->z),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x) , (float)(c->y + c->h), (float)(c->z),
(float)(c->x) , (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x) , (float)(c->y) , (float)(c->z),
(float)(c->x + c->w), (float)(c->y) , (float)(c->z),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z),
(float)(c->x) , (float)(c->y) , (float)(c->z),
(float)(c->x) , (float)(c->y + c->h), (float)(c->z),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z),
(float)(c->x) , (float)(c->y) , (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y) , (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x) , (float)(c->y) , (float)(c->z + c->d),
(float)(c->x) , (float)(c->y + c->h), (float)(c->z + c->d),
(float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d),
};
mat4 model, view, projection;
glm_mat4_identity(model);
//glm_rotate(model, (float)(c->hz_angle), (vec3){0.0f, 1.0f, 0.0f});
//glm_rotate(model, (float)(c->vt_angle), (vec3){1.0f, 0.0f, 0.0f});
//glm_translate(model, (vec3){(float)camx, (float)camy, (float)(-camz)});
//glm_translate(model, (vec3){0.0f, 0.0f, 0.0f});
vec3 dir0;
vec3 direction;
dir0[0] = sinf((float)(rot_hz)) * cosf((float)(rot_vt));
dir0[1] = -sinf((float)(rot_vt));
dir0[2] = cosf((float)(rot_hz)) * cosf((float)(rot_vt));
glm_vec3_normalize(dir0); // Normalize to unit length
glm_vec3_add((vec3){(float)camx, (float)camy, (float)camz}, dir0, direction);
glm_mat4_identity(view);
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);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, (float*)model);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "view"), 1, GL_FALSE, (float*)view);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, GL_FALSE, (float*)projection);
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);
// 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);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
}
void gl_renderCube(unsigned int shaderProgram, unsigned int VAO, unsigned int VBO, cube_0* c) {
for(int k = 0; k < 6; k++) {
gl_renderSurface(shaderProgram, VAO, VBO, c, k);
}
}
void gl_renderAll(unsigned int shaderProgram, unsigned int VAO, unsigned int VBO) {
for(int k = 0; k < current_room->map_size; k++) {
gl_renderCube(shaderProgram, VAO, VBO, current_room->map[k]);
}
for(int k = 0; k < current_room->tps_size; k++) {
gl_renderCube(shaderProgram, VAO, VBO, current_room->tps[k].hitbox);
}
for(int k = 0; k < current_room->ent_len; k++) {
gl_renderCube(shaderProgram, VAO, VBO, current_room->ents[k].pos);
}
}

View File

@ -128,19 +128,19 @@ void build_starting_chunk(int chx, int chy) {
new->tps_size = 4 ;
new->map[0] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
new->map[1] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 3.14159/8.0, 0.0, 255, 255, 255);
new->map[2] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 3.14159/4.0, 0.0, 255, 255, 255);
new->map[3] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 3.0*3.14159/8.0, 0.0, 255, 255, 255);
new->map[1] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
new->map[2] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
new->map[3] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
new->map[4] = create_cube_0(0.0, 1.0, 0.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
new->map[5] = create_cube_0(4.0, 1.0, 0.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
new->map[6] = create_cube_0(0.0, 1.0, 4.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
new->map[7] = create_cube_0(4.0, 1.0, 4.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
new->map[8] = create_cube_0(10.0, 10.0, 10.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 128, 255);
new->tps[0] = create_teleporter(-1.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 255, 0, 0 , chx-1, chy , 2.5, 2.5, 2.5);
new->tps[1] = create_teleporter(2.0, 1.0, -1.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 255, 255, 0, chx , chy-1, 2.5, 2.5, 2.5);
new->tps[2] = create_teleporter(5.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 0, 255, 0 , chx+1, chy , 2.5, 2.5, 2.5);
new->tps[3] = create_teleporter(2.0, 1.0, 5.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 0, 0, 255 , chx , chy+1, 2.5, 2.5, 2.5);
new->tps[0] = create_teleporter(-1.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 255, 0, 0 , chx-1, chy , 2.5, 2.5, 2.5);
new->tps[1] = create_teleporter(2.0, 1.0, -1.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 255, 255, 0, chx , chy-1, 2.5, 2.5, 2.5);
new->tps[2] = create_teleporter(5.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 0, 255, 0 , chx+1, chy , 2.5, 2.5, 2.5);
new->tps[3] = create_teleporter(2.0, 1.0, 5.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 0.0, 0.0, 0, 0, 255 , chx , chy+1, 2.5, 2.5, 2.5);
new->ents = malloc(sizeof(entity)*128);
new->ent_len = 1 ;

1140
src/glad.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <GL/glew.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "hash.h"
@ -25,8 +25,247 @@
double sim_time ;
void processInput(GLFWwindow *window, float dtime) {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
for(int k = 0; k < 10; k++) {
camz -= speed*cos(rot_hz)*cos(rot_vt)/10;
camx -= speed*sin(rot_hz)*cos(rot_vt)/10;
camy += speed*sin(rot_vt)/10;
if(is_colliding(dtime)) {
camz += speed*cos(rot_hz)*cos(rot_vt)/10;
camx += speed*sin(rot_hz)*cos(rot_vt)/10;
camy -= speed*sin(rot_vt)/10;
k=11;
}
}
}
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
for(int k = 0; k < 10; k++) {
camx -= speed*cos(rot_hz)/10;
camz += speed*sin(rot_hz)/10;
if(is_colliding(dtime)) {
camx += speed*cos(rot_hz)/10;
camz -= speed*sin(rot_hz)/10;
k=11;
}
}
}
if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
for(int k = 0; k < 10; k++) {
camz += speed*cos(rot_hz)*cos(rot_vt)/10;
camx += speed*sin(rot_hz)*cos(rot_vt)/10;
camy -= speed*sin(rot_vt)/10;
if(is_colliding(dtime)) {
camz -= speed*cos(rot_hz)*cos(rot_vt)/10;
camx -= speed*sin(rot_hz)*cos(rot_vt)/10;
camy += speed*sin(rot_vt)/10;
k=11;
}
}
}
if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
for(int k = 0; k < 10; k++) {
camx += speed*cos(rot_hz)/10;
camz -= speed*sin(rot_hz)/10;
if(is_colliding(dtime)) {
camx -= speed*cos(rot_hz)/10;
camz += speed*sin(rot_hz)/10;
k=11;
}
}
}
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
stop_evetything = true ;
}
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
rot_hz -= sensitivity;
}
if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) {
rot_hz += sensitivity;
}
if(glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
rot_vt -= sensitivity;
}
if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) {
rot_vt += sensitivity;
}
}
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"uniform mat4 model;\n"
"uniform mat4 view;\n"
"uniform mat4 projection;\n"
"void main() {\n"
" gl_Position = projection * view * model * vec4(aPos, 1.0);\n"
"}\0";
// Fragment Shader Source
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"void main() {\n"
" FragColor = vec4(1.0, 0.5, 0.2, 1.0);\n"
"}\0";
int main_alt() {
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glfw window creation
// --------------------
GLFWwindow* window = glfwCreateWindow(1500, 1000, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
fprintf(stderr, "ERROR : cannot initialize GL window");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// glad: load all OpenGL function pointers
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
fprintf(stderr, "ERROR : cannot initialize GLAD loader");
return -1;
}
//printf("%f\n", glDepthRange);
// build and compile our shader program
// ------------------------------------
// vertex shader
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
// check for shader compile errors
int success;
char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success)
{
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);
glCompileShader(fragmentShader);
// check for shader compile errors
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
fprintf(stderr, "ERROR : cannot initialize shader (2)");
}
// 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
// ------------------------------------------------------------------
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);
// uncomment this call to draw in wireframe polygons.
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// render loop
// -----------
init_csts();
init_hashtbl();
init_draworder();
init_ent_generator(10);
trInit();
init_proj();
parse_rooms(5);
clock_t origin = clock();
clock_t finish = clock();
while (!glfwWindowShouldClose(window)) {
// input
// -----
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
origin = clock();
generate_nearby_chunks(1);
//gl_renderTriangle(shaderProgram, VAO, VBO, -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 1.0);
gl_renderAll(shaderProgram, VAO, VBO);
//printf("01\n");
//fflush(stdout);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
finish = clock();
processInput(window, ((float)origin - (float)finish)/CLOCKS_PER_SEC);
update_entities(((float)origin - (float)finish)/CLOCKS_PER_SEC);
updateAllProj(((float)origin - (float)finish)/CLOCKS_PER_SEC);
glfwSwapBuffers(window);
glfwPollEvents();
}
for(int k = 0; k < MAX_SIZE; k++) {
free(triangles_to_render[k]);
free(triangles_og_coords[k]);
}
free(drawOrder);
free(triangles_to_render);
free(triangles_og_coords);
free(reds);
free(greens);
free(blues);
free(triangles_order);
free(triangles_shr);
free(visited_tri);
free_proj();
//printf("10\n");
//fflush(stdout);
hashtbl_free(visited);
free_pool();
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteProgram(shaderProgram);
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
int main(int argc, char** argv) {
srand(time(NULL));
return main_alt();
//-------------------------------------------------------------------------------//

View File

@ -19,7 +19,7 @@
#include "move.h"
// ---------------------------------------------------------------------------------------------------- //
double sensitivity = 0.12 ;
double sensitivity = 0.06 ;
double fov = 90.0 ;
double speed = 0.22 ;
double min_dist = 0.7 ;
@ -44,11 +44,11 @@ int fade_dmg ;
bool has_changed ;
void init_csts() {
camx = 3.0 ;
camy = 3.0 ;
camz = 3.0 ;
camx = 2.0 ;
camy = 5.0 ;
camz = 2.0 ;
rot_hz = 0.0 ;
rot_vt = 180.0*3.14159/180.0 ;
rot_vt = 0.0 ;
draw_type = 0 ;
player_hp = 1000 ;
fade_dmg = 0;

View File

@ -138,4 +138,11 @@ extern int MAX_SIZE ;
extern double shrink_distance ;
// ---------------------------------------------------------------------------------------------------- //
extern double sensitivity ;
extern double fov ;
extern double speed ;
extern double min_dist ;
// ---------------------------------------------------------------------------------------------------- //
#endif

View File

@ -22,6 +22,6 @@ Entities :
[0.0, 10.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]
Weight :
10
60
$

View File

@ -11,6 +11,6 @@ Teleporters :
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0]
Weight :
200
20
$