mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-09 21:54:09 +08:00
feat: initialize OpenGL
This commit is contained in:
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
*.o
|
||||
*.obj
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
*.a
|
||||
*.lib
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.idb
|
||||
*.pch
|
||||
*.sbr
|
||||
build/
|
||||
Build/
|
||||
bin/
|
||||
Debug/
|
||||
Release/
|
||||
x64/
|
||||
x86/
|
||||
out/
|
||||
.vs/
|
||||
.vscode/
|
||||
.idea/
|
||||
*.user
|
||||
*.suo
|
||||
*.sln.docstates
|
||||
CMakeCache.txt
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
Makefile
|
||||
CMakeOutput.log
|
||||
CMakeError.log
|
||||
*.log
|
||||
*.tmp
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
.DS_Store
|
||||
84
CMakeLists.txt
Normal file
84
CMakeLists.txt
Normal file
@@ -0,0 +1,84 @@
|
||||
cmake_minimum_required(VERSION 3.14...3.24)
|
||||
project(Cubed LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
pkg_check_modules(EGL REQUIRED egl)
|
||||
pkg_check_modules(Wayland REQUIRED wayland-client wayland-egl)
|
||||
find_package(glfw3 REQUIRED)
|
||||
|
||||
|
||||
add_library(glad STATIC third_party/glad/src/glad.c)
|
||||
target_include_directories(glad PUBLIC third_party/glad/include)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
glm
|
||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||
GIT_TAG 1.0.3
|
||||
|
||||
)
|
||||
FetchContent_MakeAvailable(glm)
|
||||
FetchContent_Declare(
|
||||
soil2
|
||||
GIT_REPOSITORY https://github.com/SpartanJ/SOIL2.git
|
||||
GIT_TAG 1.31
|
||||
|
||||
)
|
||||
FetchContent_MakeAvailable(soil2)
|
||||
|
||||
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/main.cpp
|
||||
src/tools/shader_tools.cpp
|
||||
src/tools/log.cpp
|
||||
src/camera.cpp
|
||||
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIR})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${EGL_LIBRARIES}
|
||||
${Wayland_LIBRARIES}
|
||||
glfw
|
||||
glad
|
||||
glm::glm
|
||||
OpenGL::GL
|
||||
soil2
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${EGL_INCLUDE_DIRS}
|
||||
${Wayland_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE ${EGL_CFLAGS_OTHER} ${Wayland_CFLAGS_OTHER})
|
||||
|
||||
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${PROJECT_SOURCE_DIR}/src/shaders"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/shaders"
|
||||
COMMENT "Copying shaders to output directory"
|
||||
)
|
||||
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
## What's it
|
||||
A cube game like Minecraft, using C++ and OpenGL.
|
||||
BIN
assets/texture/block/grass_block/back.png
Normal file
BIN
assets/texture/block/grass_block/back.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 B |
BIN
assets/texture/block/grass_block/base.png
Normal file
BIN
assets/texture/block/grass_block/base.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 B |
BIN
assets/texture/block/grass_block/front.png
Normal file
BIN
assets/texture/block/grass_block/front.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 B |
BIN
assets/texture/block/grass_block/left.png
Normal file
BIN
assets/texture/block/grass_block/left.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 B |
BIN
assets/texture/block/grass_block/right.png
Normal file
BIN
assets/texture/block/grass_block/right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 B |
BIN
assets/texture/block/grass_block/top.png
Normal file
BIN
assets/texture/block/grass_block/top.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 220 B |
29
include/Cubed/camera.hpp
Normal file
29
include/Cubed/camera.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
struct MoveState {
|
||||
bool forward = false;
|
||||
bool back = false;
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool down = false;
|
||||
bool up = false;
|
||||
};
|
||||
|
||||
void updateMoveCamera();
|
||||
|
||||
void cameraInit();
|
||||
|
||||
void changeView(float offsetX, float offsetY);
|
||||
|
||||
void updateCursorPositionCamera(double xpos, double ypos);
|
||||
|
||||
glm::mat4 getCameraLookAt();
|
||||
|
||||
void updateCameraKey(int key, int action);
|
||||
49
include/Cubed/tools/log.hpp
Normal file
49
include/Cubed/tools/log.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <string>
|
||||
namespace LOG {
|
||||
|
||||
template<typename... Args>
|
||||
void info(const char * fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::
|
||||
time_point_cast<std::chrono::seconds>
|
||||
(std::chrono::system_clock::now());
|
||||
|
||||
std::string msg = std::vformat(fmt, std::make_format_args(args...));
|
||||
std::cout << "\033[1;32m"
|
||||
<< std::format("[INFO][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(const char * fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::
|
||||
time_point_cast<std::chrono::seconds>
|
||||
(std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt, std::make_format_args(args...));
|
||||
std::cout << "\033[1;31m"
|
||||
<< std::format("[ERROR][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< std::endl;
|
||||
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(const char * fmt, Args&&... args) {
|
||||
auto now_time = std::chrono::
|
||||
time_point_cast<std::chrono::seconds>
|
||||
(std::chrono::system_clock::now());
|
||||
std::string msg = std::vformat(fmt, std::make_format_args(args...));
|
||||
std::cout << "\033[1;33m"
|
||||
<< std::format("[WARN][{:%Y-%m-%d %H:%M:%S}]", now_time)
|
||||
<< msg
|
||||
<< "\033[0m"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
14
include/Cubed/tools/shader_tools.hpp
Normal file
14
include/Cubed/tools/shader_tools.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <SOIL2.h>
|
||||
|
||||
void printShaderLog(GLuint shader);
|
||||
void printProgramInfo(int prog);
|
||||
bool checkOpenGLError();
|
||||
std::string readShaderSource(const char* filePath);
|
||||
GLuint loadTexture(const char* texImagePath);
|
||||
131
src/camera.cpp
Normal file
131
src/camera.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "Cubed/camera.hpp"
|
||||
|
||||
static glm::vec3 cameraPos;
|
||||
static float speed = 0.1f;
|
||||
static float lastMouseX, lastMouseY;
|
||||
static bool firseMouse = true;
|
||||
|
||||
|
||||
static MoveState moveState;
|
||||
|
||||
static float yaw, pitch;
|
||||
static glm::vec3 front = glm::vec3(0, 0, -1);
|
||||
static float sensitivity = 0.05f;
|
||||
static glm::vec3 rightPos;
|
||||
|
||||
void updateMoveCamera() {
|
||||
rightPos = glm::normalize(glm::cross(front, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
if (moveState.forward) {
|
||||
cameraPos += glm::vec3(front.x, 0.0f, front.z) * speed;
|
||||
}
|
||||
if (moveState.back) {
|
||||
cameraPos -= glm::vec3(front.x, 0.0f, front.z) * speed;
|
||||
}
|
||||
if (moveState.left) {
|
||||
cameraPos -= glm::vec3(rightPos.x, 0.0f, rightPos.z) * speed;
|
||||
}
|
||||
if (moveState.right) {
|
||||
cameraPos += glm::vec3(rightPos.x, 0.0f, rightPos.z) * speed;
|
||||
}
|
||||
if (moveState.up) {
|
||||
cameraPos += glm::vec3(0.0f, 1.0f, 0.0f) * speed;;
|
||||
}
|
||||
if (moveState.down) {
|
||||
cameraPos -= glm::vec3(0.0f, 1.0f, 0.0f) * speed;;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cameraInit() {
|
||||
cameraPos = glm::vec3(0.0f, 0.0f, 5.0f);
|
||||
}
|
||||
|
||||
void changeView(float offsetX, float offsetY) {
|
||||
yaw += offsetX * sensitivity;
|
||||
pitch += offsetY * sensitivity;
|
||||
|
||||
|
||||
if (pitch > 89.0f) pitch = 89.0f;
|
||||
if (pitch < -89.0f) pitch = -89.0f;
|
||||
|
||||
|
||||
front.x = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
|
||||
front.y = sin(glm::radians(pitch));
|
||||
front.z = -cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
||||
|
||||
front = glm::normalize(front);
|
||||
}
|
||||
|
||||
void updateCursorPositionCamera(double xpos, double ypos) {
|
||||
if (firseMouse) {
|
||||
lastMouseX = xpos;
|
||||
lastMouseY = ypos;
|
||||
firseMouse = false;
|
||||
}
|
||||
|
||||
float offsetX = xpos - lastMouseX;
|
||||
float offsetY = lastMouseY - ypos;
|
||||
|
||||
lastMouseX = xpos;
|
||||
lastMouseY = ypos;
|
||||
changeView(offsetX, offsetY);
|
||||
}
|
||||
|
||||
glm::mat4 getCameraLookAt() {
|
||||
return glm::lookAt(cameraPos, cameraPos + front, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
|
||||
void updateCameraKey(int key, int action) {
|
||||
switch(key) {
|
||||
case GLFW_KEY_W:
|
||||
if (action == GLFW_PRESS) {
|
||||
moveState.forward = true;
|
||||
}
|
||||
if (action == GLFW_RELEASE) {
|
||||
moveState.forward = false;
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_S:
|
||||
if (action == GLFW_PRESS) {
|
||||
moveState.back = true;
|
||||
}
|
||||
if (action == GLFW_RELEASE) {
|
||||
moveState.back = false;
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_A:
|
||||
if (action == GLFW_PRESS) {
|
||||
moveState.left = true;
|
||||
}
|
||||
if (action == GLFW_RELEASE) {
|
||||
moveState.left = false;
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_D:
|
||||
if (action == GLFW_PRESS) {
|
||||
moveState.right = true;
|
||||
}
|
||||
if (action == GLFW_RELEASE) {
|
||||
moveState.right = false;
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_SPACE:
|
||||
if (action == GLFW_PRESS) {
|
||||
moveState.up = true;
|
||||
}
|
||||
if (action == GLFW_RELEASE) {
|
||||
moveState.up = false;
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_LEFT_SHIFT:
|
||||
if (action == GLFW_PRESS) {
|
||||
moveState.down = true;
|
||||
}
|
||||
if (action == GLFW_RELEASE) {
|
||||
moveState.down = false;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
305
src/main.cpp
Normal file
305
src/main.cpp
Normal file
@@ -0,0 +1,305 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <Cubed/camera.hpp>
|
||||
#include <Cubed/tools/log.hpp>
|
||||
#include <Cubed/tools/shader_tools.hpp>
|
||||
|
||||
constexpr int numVAOs = 1;
|
||||
constexpr int numVBOs = 3;
|
||||
|
||||
GLuint renderingProgram;
|
||||
GLuint vao[numVAOs];
|
||||
GLuint vbo[numVBOs];
|
||||
GLuint pyrTexture;
|
||||
float cubLocX, cubLocY, cubLocZ;
|
||||
float pyLocX, pyLocY, pyLocZ;
|
||||
GLuint mvLoc, projLoc, tfLoc;
|
||||
int width ,height;
|
||||
float aspect;
|
||||
glm::mat4 pMat, vMat, mMat, mvMat;
|
||||
float inc = 0.01f;
|
||||
float tf = 0.0f;
|
||||
glm::mat4 tMat, rMat, sMat;
|
||||
|
||||
|
||||
void setupVertices(void) {
|
||||
float verticesPos[108] = {
|
||||
// ===== 后面 (z = -1) =====
|
||||
-1.0f, -1.0f, -1.0f, // 左下
|
||||
1.0f, -1.0f, -1.0f, // 右下
|
||||
1.0f, 1.0f, -1.0f, // 右上
|
||||
1.0f, 1.0f, -1.0f, // 右上
|
||||
-1.0f, 1.0f, -1.0f, // 左上
|
||||
-1.0f, -1.0f, -1.0f, // 左下
|
||||
// ===== 前面 (z = +1) =====
|
||||
-1.0f, -1.0f, 1.0f, // 左下
|
||||
-1.0f, 1.0f, 1.0f, // 左上
|
||||
1.0f, 1.0f, 1.0f, // 右上
|
||||
1.0f, 1.0f, 1.0f, // 右上
|
||||
1.0f, -1.0f, 1.0f, // 右下
|
||||
-1.0f, -1.0f, 1.0f, // 左下
|
||||
// ===== 左面 (x = -1) =====
|
||||
-1.0f, -1.0f, -1.0f, // 后下
|
||||
-1.0f, -1.0f, 1.0f, // 前下
|
||||
-1.0f, 1.0f, 1.0f, // 前上
|
||||
-1.0f, 1.0f, 1.0f, // 前上
|
||||
-1.0f, 1.0f, -1.0f, // 后上
|
||||
-1.0f, -1.0f, -1.0f, // 后下
|
||||
// ===== 右面 (x = +1) =====
|
||||
1.0f, -1.0f, 1.0f, // 前下
|
||||
1.0f, -1.0f, -1.0f, // 后下
|
||||
1.0f, 1.0f, -1.0f, // 后上
|
||||
1.0f, 1.0f, -1.0f, // 后上
|
||||
1.0f, 1.0f, 1.0f, // 前上
|
||||
1.0f, -1.0f, 1.0f, // 前下
|
||||
// ===== 上面 (y = +1) =====
|
||||
-1.0f, 1.0f, -1.0f, // 后左
|
||||
1.0f, 1.0f, -1.0f, // 后右
|
||||
1.0f, 1.0f, 1.0f, // 前右
|
||||
1.0f, 1.0f, 1.0f, // 前右
|
||||
-1.0f, 1.0f, 1.0f, // 前左
|
||||
-1.0f, 1.0f, -1.0f, // 后左
|
||||
// ===== 下面 (y = -1) =====
|
||||
-1.0f, -1.0f, 1.0f, // 前左
|
||||
1.0f, -1.0f, 1.0f, // 前右
|
||||
1.0f, -1.0f, -1.0f, // 后右
|
||||
1.0f, -1.0f, -1.0f, // 后右
|
||||
-1.0f, -1.0f, -1.0f, // 后左
|
||||
-1.0f, -1.0f, 1.0f // 前左
|
||||
};
|
||||
|
||||
float tex_coords[72] {
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
|
||||
};
|
||||
|
||||
|
||||
glGenVertexArrays(numVAOs, vao);
|
||||
glBindVertexArray(vao[0]);
|
||||
glGenBuffers(numVBOs, vbo);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verticesPos), verticesPos, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords), tex_coords, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
GLuint createShaderProgram() {
|
||||
std::string vShaderStr = readShaderSource("shaders/vShader.glsl");
|
||||
std::string fShaderStr = readShaderSource("shaders/fShader.glsl");
|
||||
const char *vshaderSource = vShaderStr.c_str();
|
||||
const char *fshaderSource = fShaderStr.c_str();
|
||||
|
||||
GLuint vShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
GLint vc, fc;
|
||||
glShaderSource(vShader, 1, &vshaderSource, NULL);
|
||||
glShaderSource(fShader, 1, &fshaderSource, NULL);
|
||||
glCompileShader(vShader);
|
||||
checkOpenGLError();
|
||||
glGetShaderiv(vShader, GL_COMPILE_STATUS, &vc);
|
||||
if (vc != 1) {
|
||||
LOG::error("vertex compilation failed");
|
||||
printShaderLog(vShader);
|
||||
}
|
||||
glCompileShader(fShader);
|
||||
checkOpenGLError();
|
||||
glGetShaderiv(fShader, GL_COMPILE_STATUS, &fc);
|
||||
if (fc != 1) {
|
||||
LOG::error("vertex compilation failed");
|
||||
printShaderLog(fShader);
|
||||
}
|
||||
GLuint vfProgram = glCreateProgram();
|
||||
glAttachShader(vfProgram, vShader);
|
||||
glAttachShader(vfProgram, fShader);
|
||||
glLinkProgram(vfProgram);
|
||||
|
||||
GLint linked;
|
||||
checkOpenGLError();
|
||||
glGetProgramiv(vfProgram, GL_LINK_STATUS, &linked);
|
||||
if (linked != 1) {
|
||||
LOG::error("linking failed");
|
||||
printProgramInfo(vfProgram);
|
||||
}
|
||||
|
||||
return vfProgram;
|
||||
}
|
||||
|
||||
|
||||
void init(GLFWwindow* window) {
|
||||
renderingProgram = createShaderProgram();
|
||||
|
||||
cubLocX = 0.0f;
|
||||
cubLocY = -2.0f;
|
||||
cubLocZ = 0.0f;
|
||||
pyLocX = 0.0f;
|
||||
pyLocY = -2.0f;
|
||||
pyLocZ = -20.0f;
|
||||
cameraInit();
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
aspect = (float)width / (float)height;
|
||||
glViewport(0, 0, width, height);
|
||||
pMat = glm::perspective(glm::radians(60.0f), aspect, 0.1f, 1000.0f);
|
||||
|
||||
pyrTexture = loadTexture("assets/texture/block/grass_block/top.png");
|
||||
setupVertices();
|
||||
|
||||
}
|
||||
|
||||
void window_reshape_callback(GLFWwindow* window, int newWidth, int newHeight) {
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
aspect = (float)width / (float)height;
|
||||
glViewport(0, 0, width, height);
|
||||
pMat = glm::perspective(glm::radians(60.0f), aspect, 0.1f, 1000.0f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) {
|
||||
updateCursorPositionCamera(xpos, ypos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void display(GLFWwindow* window, double currentTime) {
|
||||
|
||||
updateMoveCamera();
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glUseProgram(renderingProgram);
|
||||
|
||||
|
||||
|
||||
mvLoc = glGetUniformLocation(renderingProgram, "mv_matrix");
|
||||
projLoc = glGetUniformLocation(renderingProgram, "proj_matrix");
|
||||
|
||||
/*
|
||||
cameraX += inc;
|
||||
if (cameraX > 1.0f) {
|
||||
inc = -inc;
|
||||
}
|
||||
if (cameraX < -1.0f) {
|
||||
inc = -inc;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
glBindVertexArray(vao[0]);
|
||||
|
||||
//sMat = glm::scale(glm::mat4(1.0f), glm::vec3(0.3f, 0.3f, 0.3f));
|
||||
mMat = glm::translate(glm::mat4(1.0f), glm::vec3(pyLocX, pyLocY, pyLocZ));
|
||||
vMat = getCameraLookAt();
|
||||
mvMat = vMat * mMat;
|
||||
glUniformMatrix4fv(mvLoc, 1, GL_FALSE, glm::value_ptr(mvMat));
|
||||
glUniformMatrix4fv(projLoc, 1 ,GL_FALSE, glm::value_ptr(pMat));
|
||||
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, pyrTexture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
//glPointSize(30.0f);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
}
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
switch(key) {
|
||||
case GLFW_KEY_ESCAPE:
|
||||
if (action == GLFW_PRESS) {
|
||||
|
||||
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
} else if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL) {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
updateCameraKey(key, action);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
if (!glfwInit()) {
|
||||
LOG::error("glfwinit fail");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
GLFWwindow* window = glfwCreateWindow(800, 600, "Cubed", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
LOG::error("Failed to initialize glad");
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG::info("OpenGL Version: {}.{}", GLVersion.major, GLVersion.minor);
|
||||
LOG::info("Renderer: {}", reinterpret_cast<const char*>(glGetString(GL_RENDERER)));
|
||||
|
||||
glfwSwapInterval(1);
|
||||
glfwSetWindowSizeCallback(window, window_reshape_callback);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
init(window);
|
||||
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
display(window, glfwGetTime());
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
12
src/shaders/fShader.glsl
Normal file
12
src/shaders/fShader.glsl
Normal file
@@ -0,0 +1,12 @@
|
||||
#version 430
|
||||
|
||||
in vec2 tc;
|
||||
in vec4 varyingColor;
|
||||
out vec4 color;
|
||||
|
||||
layout (binding = 0) uniform sampler2D samp;
|
||||
|
||||
void main(void) {
|
||||
color = texture(samp, tc);
|
||||
//color = varyingColor;
|
||||
}
|
||||
63
src/shaders/vShader.glsl
Normal file
63
src/shaders/vShader.glsl
Normal file
@@ -0,0 +1,63 @@
|
||||
#version 430
|
||||
|
||||
layout (location = 0) in vec3 pos;
|
||||
layout (location = 1) in vec2 texCoord;
|
||||
out vec2 tc;
|
||||
|
||||
|
||||
mat4 buildRotateX(float rad);
|
||||
mat4 buildRotateY(float rad);
|
||||
mat4 buildRotateZ(float rad);
|
||||
mat4 buildTranslate(float x, float y, float z);
|
||||
|
||||
uniform mat4 mv_matrix;
|
||||
uniform mat4 proj_matrix;
|
||||
out vec4 varyingColor;
|
||||
|
||||
layout (binding = 0) uniform sampler2D samp;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = proj_matrix * mv_matrix * vec4(pos, 1.0);
|
||||
tc = texCoord;
|
||||
varyingColor = vec4(pos, 1.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
mat4 buildTranslate(float x, float y, float z) {
|
||||
mat4 trans = mat4(
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
x, y, z, 1.0
|
||||
);
|
||||
return trans;
|
||||
}
|
||||
|
||||
mat4 buildRotateX(float rad) {
|
||||
mat4 xrot = mat4(
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, cos(rad), -sin(rad), 0.0,
|
||||
0.0, sin(rad), cos(rad), 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
);
|
||||
return xrot;
|
||||
}
|
||||
|
||||
mat4 buildRotateY(float rad) {
|
||||
mat4 yrot = mat4(
|
||||
cos(rad), 0.0, sin(rad), 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
-sin(rad), 0.0, cos(rad), 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
);
|
||||
return yrot;
|
||||
}
|
||||
|
||||
mat4 buildRotateZ(float rad) {
|
||||
mat4 zrot = mat4(
|
||||
cos(rad), -sin(rad), 0.0, 0.0,
|
||||
sin(rad), cos(rad), 0.0, 0.0,
|
||||
0.0, 0.0,1.0 , 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
);
|
||||
return zrot;
|
||||
}
|
||||
6
src/tools/log.cpp
Normal file
6
src/tools/log.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <Cubed/tools/log.hpp>
|
||||
|
||||
namespace LOG {
|
||||
|
||||
|
||||
}
|
||||
72
src/tools/shader_tools.cpp
Normal file
72
src/tools/shader_tools.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <Cubed/tools/shader_tools.hpp>
|
||||
#include <Cubed/tools/log.hpp>
|
||||
|
||||
|
||||
|
||||
void printShaderLog(GLuint shader) {
|
||||
int len = 0;
|
||||
int chWritten = 0;
|
||||
char *log;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
|
||||
if (len > 0) {
|
||||
log = (char*)malloc(len);
|
||||
glGetShaderInfoLog(shader, len, &chWritten, log);
|
||||
LOG::info("Shader Info Log: {}", log);
|
||||
free(log);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void printProgramInfo(int prog) {
|
||||
int len = 0;
|
||||
int chWritten = 0;
|
||||
char *log;
|
||||
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &len);
|
||||
if (len > 0) {
|
||||
log = (char*)malloc(len);
|
||||
glGetProgramInfoLog(prog, len, &chWritten, log);
|
||||
LOG::info("Program Info Log: {}", log);
|
||||
free(log);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkOpenGLError() {
|
||||
bool foundError = false;
|
||||
int glErr = glGetError();
|
||||
while (glErr != GL_NO_ERROR) {
|
||||
LOG::error("glEorr: {}", glErr);
|
||||
foundError = true;
|
||||
glErr = glGetError();
|
||||
}
|
||||
|
||||
return foundError;
|
||||
}
|
||||
|
||||
|
||||
std::string readShaderSource(const char* filePath) {
|
||||
std::string content;
|
||||
std::ifstream fileStream(filePath, std::ios::in);
|
||||
|
||||
if (!fileStream.is_open()) {
|
||||
LOG::error("file not exist");
|
||||
}
|
||||
|
||||
std::string line = "";
|
||||
while (!fileStream.eof()) {
|
||||
|
||||
getline(fileStream, line);
|
||||
content.append(line + "\n");
|
||||
}
|
||||
fileStream.close();
|
||||
return content;
|
||||
}
|
||||
|
||||
GLuint loadTexture(const char* texImagePath) {
|
||||
GLuint textureID;
|
||||
textureID = SOIL_load_OGL_texture(texImagePath, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
|
||||
if (textureID == 0) {
|
||||
LOG::error("could not find texture file");
|
||||
}
|
||||
return textureID;
|
||||
}
|
||||
311
third_party/glad/include/KHR/khrplatform.h
vendored
Normal file
311
third_party/glad/include/KHR/khrplatform.h
vendored
Normal 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_ */
|
||||
3202
third_party/glad/include/glad/glad.h
vendored
Normal file
3202
third_party/glad/include/glad/glad.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1545
third_party/glad/src/glad.c
vendored
Normal file
1545
third_party/glad/src/glad.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user