v0.2.2 push
This commit is contained in:
parent
cfbe487320
commit
6b0ec93bd5
14 changed files with 21186 additions and 2 deletions
5637
Libraries/GLFW/glfw3.h
Normal file
5637
Libraries/GLFW/glfw3.h
Normal file
File diff suppressed because it is too large
Load diff
1840
Libraries/glad/glad.c
Normal file
1840
Libraries/glad/glad.c
Normal file
File diff suppressed because it is too large
Load diff
3611
Libraries/glad/glad.h
Normal file
3611
Libraries/glad/glad.h
Normal file
File diff suppressed because it is too large
Load diff
290
Libraries/glad/khrplatform.h
Normal file
290
Libraries/glad/khrplatform.h
Normal file
|
@ -0,0 +1,290 @@
|
|||
#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(KHRONOS_STATIC)
|
||||
/* 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
|
||||
|
||||
#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 _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
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_ */
|
7656
Libraries/stb/stb_image.h
Normal file
7656
Libraries/stb/stb_image.h
Normal file
File diff suppressed because it is too large
Load diff
1690
Libraries/stb/stb_image_write.h
Normal file
1690
Libraries/stb/stb_image_write.h
Normal file
File diff suppressed because it is too large
Load diff
35
README.md
35
README.md
|
@ -1,7 +1,38 @@
|
|||
|
||||
# EnginPasTangible
|
||||
|
||||
Moteur graphique qu'est pas croyable tellement qu'il est bien développé par *Victor LASSERRE* et *Valentin SERVIERES*
|
||||
Moteur graphique qu'est pas croyable tellement qu'il est bien !<br>
|
||||
> développé par *Victor LASSERRE* et *Valentin SERVIERES*
|
||||
|
||||
![Logo d'EnginPasTangible](/assets/enginpastangible.png)
|
||||
|
||||
---
|
||||
Le projet est en cours de création, plus d'infos pour l'installer plus tard.
|
||||
Le projet est en cours de création, il peut y avoir des bugs.
|
||||
|
||||
## Installation
|
||||
|
||||
Pour pouvoir utiliser le moteur il vous suffit d'installer les librairies glfw
|
||||
> ### Linux
|
||||
* Pour les distributions Debian :
|
||||
|
||||
`sudo apt install libglfw3-dev`
|
||||
* Pour Arch Linux :
|
||||
|
||||
Si vous utilisez X11 (recommandé) : `sudo pacman -Sy glfw-x11`
|
||||
|
||||
Si vous utilisez Wayland : `sudo pacman -Sy glfw-wayland`
|
||||
|
||||
Dans le repertoire de votre choix
|
||||
|
||||
`git clone https://git.etud.insa-toulouse.fr/serviere/EnginPasTangible.git`
|
||||
|
||||
`cd EnginPasTangible/`
|
||||
|
||||
`chmod +x run_linux.sh`
|
||||
|
||||
Pour compiler et exécuter le programme utilisez `./run_linux main.c`
|
||||
|
||||
Utilisez `git pull origin master` pour mettre à jour votre version du moteur graphique
|
||||
|
||||
> ### Windows & MacOs
|
||||
Essayez d'adapter les méthodes vues ci-dessus, aucune garantie que cela fonctionne.
|
BIN
assets/enginpastangible.png
Normal file
BIN
assets/enginpastangible.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
84
headers/shader.h
Normal file
84
headers/shader.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
int buildShaders(int foo, const char *vertexShaderSourceParam, const char *fragmentShaderSourceParam){
|
||||
printf("building shaders...\n");
|
||||
// build and compile our shader program
|
||||
// ------------------------------------
|
||||
|
||||
// open file and convert it to string for vs:
|
||||
char * vbuffer = 0;
|
||||
long vlength;
|
||||
FILE * vertex_file = fopen (vertexShaderSourceParam, "rb");
|
||||
|
||||
if (vertex_file)
|
||||
{
|
||||
fseek (vertex_file, 0, SEEK_END);
|
||||
vlength = ftell (vertex_file);
|
||||
fseek (vertex_file, 0, SEEK_SET);
|
||||
vbuffer = malloc (vlength + 1);
|
||||
if (vbuffer)
|
||||
{
|
||||
fread (vbuffer, 1, vlength, vertex_file);
|
||||
}
|
||||
fclose (vertex_file);
|
||||
vbuffer[vlength] = '\0';
|
||||
}
|
||||
|
||||
char * fbuffer = 0;
|
||||
long flength;
|
||||
FILE * fragment_file = fopen (fragmentShaderSourceParam, "rb");
|
||||
|
||||
if (fragment_file)
|
||||
{
|
||||
fseek (fragment_file, 0, SEEK_END);
|
||||
flength = ftell (fragment_file);
|
||||
fseek (fragment_file, 0, SEEK_SET);
|
||||
fbuffer = malloc (flength + 1);
|
||||
if (fbuffer)
|
||||
{
|
||||
fread (fbuffer, 1, flength, fragment_file);
|
||||
}
|
||||
fclose (fragment_file);
|
||||
fbuffer[flength] = '\0';
|
||||
}
|
||||
|
||||
// vertex shader
|
||||
int vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertexShader, 1, &vbuffer, 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);
|
||||
printf("ERROR::SHADER::VERTEX::COMPILATION_FAILED\n %s", infoLog);
|
||||
return 1;
|
||||
}
|
||||
// fragment shader
|
||||
int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragmentShader, 1, &fbuffer, NULL);
|
||||
glCompileShader(fragmentShader);
|
||||
// check for shader compile errors
|
||||
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
|
||||
printf("ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n %s", infoLog);
|
||||
return 2;
|
||||
}
|
||||
// link shaders
|
||||
// int shaderProgram = glCreateProgram();
|
||||
glAttachShader(foo, vertexShader);
|
||||
glAttachShader(foo, fragmentShader);
|
||||
glLinkProgram(foo);
|
||||
// check for linking errors
|
||||
glGetProgramiv(foo, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(foo, 512, NULL, infoLog);
|
||||
printf("ERROR::SHADER::PROGRAM::LINKING_FAILED\n %s", infoLog);
|
||||
return 3;
|
||||
}
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
return 0;
|
||||
}
|
212
main.c
Normal file
212
main.c
Normal file
|
@ -0,0 +1,212 @@
|
|||
#include "./Libraries/glad/glad.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "./Libraries/GLFW/glfw3.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "./Libraries/stb/stb_image.h"
|
||||
#include "headers/shader.h"
|
||||
#define FULLSCREEN 0
|
||||
|
||||
GLuint screenWidth = 720, screenHeight = 480;
|
||||
const GLFWvidmode* mode;
|
||||
GLFWwindow* window;
|
||||
|
||||
void setupVAO();
|
||||
//GLuint getTextureHandle(char* path);
|
||||
unsigned int VAO;
|
||||
|
||||
float currentTime, deltaTime, lastFrame,startTime;
|
||||
|
||||
int main (){
|
||||
|
||||
// Window setup
|
||||
GLint glfwStatus = glfwInit();
|
||||
|
||||
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
//// glfwWindowHint(GLFW_SAMPLES, 4);
|
||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);//#####
|
||||
//glfwWindowHint(GLFW_DECORATED,GL_FALSE);
|
||||
//glfwWindowHint(GLFW_CONTEXT_NO_ERROR,GL_FALSE);
|
||||
|
||||
window = glfwCreateWindow(screenWidth, screenHeight, "EnginPasTangible (alpha 0.2.2)", NULL, NULL);
|
||||
|
||||
if (window == NULL)
|
||||
{
|
||||
printf("Window failed to create");
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
//glfwSwapInterval(1); // To my knowledge, this turns on vsync on macOS
|
||||
|
||||
// If Windows or Linux: load all OpenGL function pointers with GLAD
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
printf("Failed to initialize GLAD");
|
||||
return -1;
|
||||
}
|
||||
// END Window setup
|
||||
|
||||
// set up Vertex Array Object that contains our vertices and bind it
|
||||
setupVAO();
|
||||
glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to unbind in the setupVertexArray function and then bind here, but we'll do so for clarity, organization, and avoiding possible bugs in future
|
||||
|
||||
GLuint quad_shader = glCreateProgram();
|
||||
int compilerInfo=buildShaders(quad_shader, "shaders/generic.vs", "shaders/quad.fs");
|
||||
if(compilerInfo>0){
|
||||
return compilerInfo;
|
||||
}
|
||||
glUseProgram(quad_shader);
|
||||
|
||||
//GLuint channel_logo = getTextureHandle("assets/logo.png");
|
||||
//glBindTexture(GL_TEXTURE_2D, channel_logo);
|
||||
|
||||
// for alpha (opacity)
|
||||
//glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// GLFWimage images[2];
|
||||
// images[0] = load_icon("assets/enginpastangible.png");
|
||||
// images[1] = load_icon("assets/icon.png");
|
||||
|
||||
// glfwSetWindowIcon(window, 2, images);
|
||||
|
||||
GLFWimage images[1];
|
||||
images[0].pixels = stbi_load("./assets/icon.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
|
||||
glfwSetWindowIcon(window, 1, images);
|
||||
stbi_image_free(images[0].pixels);
|
||||
|
||||
int window_width, window_height;
|
||||
float mousePosX,mousePosY,camPosX,camPosY,camPosZ,camDirX,camDirY,camDirZ;
|
||||
char FPS[20];
|
||||
startTime = glfwGetTime();
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
|
||||
currentTime = glfwGetTime();
|
||||
deltaTime = currentTime - lastFrame;
|
||||
lastFrame = currentTime;
|
||||
gcvt(1/deltaTime,4,FPS);
|
||||
printf("FPS : %s\n",FPS);
|
||||
|
||||
glfwGetWindowSize(window, &window_width, &window_height);
|
||||
glViewport(0, 0, window_width, window_height);
|
||||
// printf("%d\n", window_width);
|
||||
|
||||
glClearColor(0.9f, 0.9f, 0.2f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
glUniform1f(glGetUniformLocation(quad_shader, "iTime"), currentTime-startTime);
|
||||
glUniform2f(glGetUniformLocation(quad_shader, "iMousePos"), mousePosX,mousePosY);
|
||||
glUniform3f(glGetUniformLocation(quad_shader, "iCamPos"), camPosX,camPosY,camPosZ);
|
||||
glUniform3f(glGetUniformLocation(quad_shader, "iCamDir"), camDirX,camDirY,camDirZ);
|
||||
|
||||
// glBindVertexArray(0); // no need to unbind it every time
|
||||
|
||||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||
// -------------------------------------------------------------------------------
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
}
|
||||
|
||||
// Optional cleaning up bc OS will likely do it for us, but is a good practice. Note that shaders are deleted in shader.h
|
||||
|
||||
glDeleteProgram(quad_shader);
|
||||
|
||||
// glfw: terminate, clearing all previously allocated GLFW resources.
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void setupVAO(){
|
||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||
// ------------------------------------------------------------------
|
||||
float vertices[] = {
|
||||
// positions // textures
|
||||
1.f, 1.0f, 0.0f, 1.5f, 1.0f, // top right
|
||||
1.f, -1.f, 0.0f, 1.5f, -1.0f, // bottom right/////-1 => 0.
|
||||
-1.f, -1.f, 0.0f, -1.5f, -1.0f, // bottom left
|
||||
-1.f, 1.f, 0.0f, -1.5f, 1.0f // top left
|
||||
};
|
||||
|
||||
unsigned int indices[] = {
|
||||
0, 1, 3, // first Triangle
|
||||
1, 2, 3 // second Triangle
|
||||
};
|
||||
|
||||
unsigned int VBO, EBO;
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenBuffers(1, &EBO);
|
||||
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||
|
||||
// Position attribute
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
// TexCoord attribute
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_TRUE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
// remember: do NOT unbind the EBO while a VAO is active as the bound element buffer object IS stored in the VAO; keep the EBO bound.
|
||||
//glBindBuffer(GL_ELEMENT_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);
|
||||
}
|
||||
/*
|
||||
GLuint getTextureHandle(char* path)
|
||||
{
|
||||
GLuint textureHandle;
|
||||
glGenTextures(1, &textureHandle);
|
||||
glBindTexture(GL_TEXTURE_2D, textureHandle); // All upcoming GL_TEXTURE_2D operations now have effect on our texture object
|
||||
|
||||
// Set our texture parameters
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture wrapping to GL_REPEAT
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); // Set texture wrapping to GL_CLAMP_TO_BORDER
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
|
||||
// Set texture filtering
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// Load, create texture and generate mipmaps;
|
||||
//
|
||||
// Note: image loaders usually think of top left as being (0,0) while in OpenGL I would rather think of bottom left as being (0,0) as OpenGL does that already, so that is why I set the stb library to flip image vertically. There are other workarounds like flipping our texCoords upside down or flipping things in the vs or fs, but that would mean that we are choosing in OpenGL to work with two different coordinate systems, one upside-down from the other. I would rather choose not to do that and simply flip images when loading in. It is a matter of personal choice.
|
||||
//
|
||||
|
||||
int width, height, nrChannels;
|
||||
stbi_set_flip_vertically_on_load(1);
|
||||
unsigned char *image = stbi_load(path, &width, &height, &nrChannels, 0);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
// free memory
|
||||
stbi_image_free(image);
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // unbind so that we can deal with other textures
|
||||
|
||||
return textureHandle;
|
||||
}
|
||||
*/
|
||||
|
22
run_linux.sh
Executable file
22
run_linux.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
|
||||
# takes an argument for compilation
|
||||
LD_LIBRARY_PATH=$(pwd) ./a.out
|
||||
# Exits and displays error if there is no argument provided
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "This script requires an argument."
|
||||
echo "Please provide the C file that you wish to compile."
|
||||
echo "Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if the a.out file already exists, move it to .a.out. Program should not execute if it does not compile properly.
|
||||
FILE=a.out
|
||||
if test -f "$FILE"; then
|
||||
mv a.out .a.out
|
||||
fi
|
||||
|
||||
# If it doesn't work for you, try adding any of the libraries below.
|
||||
#gcc $1 -lGL -lm -lX11 -lpthread -lXrandr -lXi -ldl -lglfw
|
||||
gcc $1 -lGL -lm -ldl ./Libraries/glad/glad.c ./Libraries/GLFW/Linux/libglfw.so.3.3
|
||||
./a.out
|
||||
|
26
shaders/generic.vs
Normal file
26
shaders/generic.vs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 2) in vec2 texCoord;
|
||||
|
||||
out vec2 FragCoord;
|
||||
out float Time;
|
||||
out vec2 MousePos;
|
||||
out vec3 CamPos;
|
||||
out vec3 CamDir;
|
||||
|
||||
uniform float iTime;
|
||||
uniform vec2 iMousePos;
|
||||
uniform vec3 iCamPos;
|
||||
uniform vec3 iCamDir;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||
FragCoord = texCoord;
|
||||
Time=iTime;
|
||||
MousePos = iMousePos;
|
||||
CamPos = iCamPos;
|
||||
CamDir = iCamDir;
|
||||
}
|
85
shaders/quad.fs
Normal file
85
shaders/quad.fs
Normal file
|
@ -0,0 +1,85 @@
|
|||
#version 330 core
|
||||
|
||||
in vec2 FragCoord;
|
||||
in float Time;
|
||||
in vec2 MousePos;
|
||||
in vec3 CamPos;
|
||||
in vec3 CamDir;
|
||||
|
||||
out vec4 FragColor;
|
||||
//uniform sampler2D generalTexture;
|
||||
|
||||
float SDF_Box_Frame( vec3 p, vec3 b, float e )
|
||||
{
|
||||
p = abs(p )-b;
|
||||
vec3 q = abs(p+e)-e;
|
||||
return min(min(
|
||||
length(max(vec3(p.x,q.y,q.z),0.0))+min(max(p.x,max(q.y,q.z)),0.0),
|
||||
length(max(vec3(q.x,p.y,q.z),0.0))+min(max(q.x,max(p.y,q.z)),0.0)),
|
||||
length(max(vec3(q.x,q.y,p.z),0.0))+min(max(q.x,max(q.y,p.z)),0.0));
|
||||
}
|
||||
|
||||
float SDF_Circle(vec3 p,float r){
|
||||
return length(p)-r;
|
||||
}
|
||||
|
||||
float SDF_Global(vec3 p){
|
||||
return min(SDF_Box_Frame(p,vec3(.5,.5,.5),0.1),SDF_Circle(mod(p+vec3(.5),vec3(1.,1.,1.))-vec3(.5),.15));
|
||||
}
|
||||
|
||||
vec4 Get_Impact(vec3 origin,vec3 dir){//must have length(dir)==1
|
||||
vec3 pos=origin;
|
||||
float dist;
|
||||
for(int i=0;i<30;i++){
|
||||
dist=SDF_Global(pos);
|
||||
pos+=dist*dir;
|
||||
if(dist<=.01) return vec4(pos,1.);
|
||||
if(dist>=20.0) return vec4(pos,-1.);
|
||||
}
|
||||
return vec4(pos,-1.);
|
||||
}
|
||||
|
||||
vec3 grad(vec3 p){
|
||||
vec2 epsilon = vec2(.01,0.);
|
||||
return normalize(vec3(SDF_Global(p+epsilon.xyy)-SDF_Global(p-epsilon.xyy),
|
||||
SDF_Global(p+epsilon.yxy)-SDF_Global(p-epsilon.yxy),
|
||||
SDF_Global(p+epsilon.yyx)-SDF_Global(p-epsilon.yyx)));
|
||||
}
|
||||
|
||||
vec3 Get_Color(vec3 origin,vec3 dir){
|
||||
vec4 impact = Get_Impact(origin,dir);
|
||||
if(impact.w<0.) return vec3(.5,.7,1.);
|
||||
vec3 normale=grad(impact.xyz);
|
||||
return normale;
|
||||
}
|
||||
|
||||
float Mandel(vec2 co){
|
||||
vec2 coo = co.xy;
|
||||
float limf=100.0;
|
||||
float cf=0.0;
|
||||
int c;
|
||||
for(c=0;c<100;c++){
|
||||
coo=vec2(pow(coo.x,2.0)-pow(coo.y,2.0)+co.x,2.*coo.x*coo.y+co.y);
|
||||
if(length(coo)>=2.0){
|
||||
return cf/limf;
|
||||
}
|
||||
cf+=1.0;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lookingAt = vec3(0.,0.,0.);
|
||||
vec3 posCam = vec3(3.*sin(Time*.5),0.,3.*cos(Time*.5));
|
||||
|
||||
vec3 ez = normalize(lookingAt-posCam);////base orthonormée
|
||||
vec3 ex = normalize(cross(ez,vec3(0.,1.,0.)));
|
||||
vec3 ey = cross(ex,ez);
|
||||
|
||||
vec3 dir = normalize(FragCoord.x * ex + FragCoord.y*ey + 1.*ez);
|
||||
|
||||
|
||||
//float c=Mandel(FragCoord*1.5);
|
||||
FragColor=vec4(Get_Color(posCam,dir),1.);//c,c,c,1.);
|
||||
}
|
Loading…
Reference in a new issue