2024-11-30 14:26:28 +00:00
# if 1
# include <Windows.h>
# include <iostream>
# include <glm/glm.hpp>
# include <glm/ext.hpp>
# include <stb/stb_image.h>
# include "Core/Logger.h"
# include "Ipc/IpcMoudle.h"
2024-12-01 17:31:51 +00:00
# include "ImageBuffer.h"
2024-11-30 14:26:28 +00:00
# include "shader_s.h"
2024-12-01 17:31:51 +00:00
# include "Texture2D.h"
2024-11-30 14:26:28 +00:00
static int APIENTRY wWinMain ( _In_ HINSTANCE hInstance , _In_opt_ HINSTANCE hPrevInstance , _In_ LPWSTR lpCmdLine , _In_ int nCmdShow ) {
Logger : : Init ( ) ;
IpcMoudle : : Init ( ) ;
2024-12-01 17:31:51 +00:00
ImageBuffer : : Init ( ) ;
2024-11-30 14:26:28 +00:00
auto glfwErrorCallback = [ ] ( int error , const char * description ) {
ERRORLOG ( " code={}, description={} " , error , description ) ;
} ;
glfwSetErrorCallback ( glfwErrorCallback ) ;
if ( GLFW_TRUE ! = glfwInit ( ) ) {
return - 1 ; //exit(EXIT_FAILURE);
}
glfwWindowHint ( GLFW_CONTEXT_VERSION_MAJOR , 4 ) ;
glfwWindowHint ( GLFW_CONTEXT_VERSION_MINOR , 4 ) ;
glfwWindowHint ( GLFW_OPENGL_PROFILE , GLFW_OPENGL_CORE_PROFILE ) ;
glfwWindowHint ( GLFW_SAMPLES , 4 ) ;
if ( true ) {
glfwWindowHint ( GLFW_OPENGL_DEBUG_CONTEXT , GL_TRUE ) ;
}
glfwWindowHint ( GLFW_RESIZABLE , true ) ;
glfwWindowHint ( GLFW_DECORATED , true ) ;
glfwWindowHint ( GLFW_FOCUSED , true ) ;
glfwWindowHint ( GLFW_MAXIMIZED , false ) ;
glfwWindowHint ( GLFW_FLOATING , false ) ;
glfwWindowHint ( GLFW_VISIBLE , true ) ;
glfwWindowHint ( GLFW_AUTO_ICONIFY , true ) ;
//glfwWindowHint(GLFW_REFRESH_RATE, settings.refreshRate);
glfwWindowHint ( GLFW_SAMPLES , 4 ) ;
GLFWwindow * window = glfwCreateWindow ( 860 , 540 , " humanRender " , nullptr , nullptr ) ;
if ( ! window ) {
ERRORLOG ( " glfwCreateWindow failed " ) ;
glfwTerminate ( ) ;
return false ;
}
glfwSetKeyCallback ( window , [ ] ( GLFWwindow * window , int key , int scancode , int action , int mods ) {
if ( key = = GLFW_KEY_ESCAPE & & action = = GLFW_PRESS )
glfwSetWindowShouldClose ( window , GLFW_TRUE ) ;
}
) ;
glfwMakeContextCurrent ( window ) ;
glewExperimental = GL_TRUE ;
GLenum err = glewInit ( ) ;
if ( GLEW_OK ! = err ) {
const GLubyte * errorString = glewGetErrorString ( err ) ;
ERRORLOG ( " glewInit={1}, err={2} " , err , reinterpret_cast < const char * > ( errorString ) ) ;
glfwDestroyWindow ( window ) ;
glfwTerminate ( ) ;
return - 1 ;
}
glfwSwapInterval ( 1 ) ;
float vertices [ ] = {
// positions // colors // texture coords
1.0f , 1.0f , 0.0f , 1.0f , 0.0f , 0.0f , 1.0f , 1.0f , // top right
1.0f , - 1.0f , 0.0f , 0.0f , 1.0f , 0.0f , 1.0f , 0.0f , // bottom right
- 1.0f , - 1.0f , 0.0f , 0.0f , 0.0f , 1.0f , 0.0f , 0.0f , // bottom left
- 1.0f , 1.0f , 0.0f , 1.0f , 1.0f , 0.0f , 0.0f , 1.0f // top left
} ;
unsigned int indices [ ] = {
0 , 1 , 3 , // first triangle
1 , 2 , 3 // second triangle
} ;
unsigned int VBO , VAO , 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 ) ;
glVertexAttribPointer ( 0 , 3 , GL_FLOAT , GL_FALSE , 8 * sizeof ( float ) , ( void * ) 0 ) ;
glEnableVertexAttribArray ( 0 ) ;
glVertexAttribPointer ( 1 , 3 , GL_FLOAT , GL_FALSE , 8 * sizeof ( float ) , ( void * ) ( 3 * sizeof ( float ) ) ) ;
glEnableVertexAttribArray ( 1 ) ;
glVertexAttribPointer ( 2 , 2 , GL_FLOAT , GL_FALSE , 8 * sizeof ( float ) , ( void * ) ( 6 * sizeof ( float ) ) ) ;
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 ) ;
2024-12-01 17:31:51 +00:00
Texture2D background ;
2024-11-30 14:26:28 +00:00
int width , height , nrChannels ;
// The FileSystem::getPath(...) is part of the GitHub repository so we can find files on any IDE/platform; replace it with your own image path.
unsigned char * data = stbi_load ( " ./data/background/background.jpg " , & width , & height , & nrChannels , 0 ) ;
if ( data ) {
2024-12-01 17:31:51 +00:00
background . Create ( width , height , nrChannels , nullptr ) ;
background . Update ( width , height , nrChannels , data ) ;
2024-11-30 14:26:28 +00:00
} else {
std : : cout < < " Failed to load texture " < < std : : endl ;
}
stbi_image_free ( data ) ;
2024-12-02 15:01:10 +00:00
int32 imageWidth = 1080 ;
int32 imageHeight = 1920 ;
2024-12-01 17:31:51 +00:00
Texture2D huaman ;
2024-12-02 15:01:10 +00:00
huaman . Create ( imageWidth , imageHeight , 4 , nullptr ) ;
2024-11-30 14:26:28 +00:00
Shader shader ( " ./data/shader/texture.vs " , " ./data/shader/texture.fs " ) ;
2024-12-01 17:31:51 +00:00
shader . use ( ) ;
shader . setInt ( " background " , 0 ) ;
shader . setInt ( " human " , 1 ) ;
2024-11-30 14:26:28 +00:00
while ( ! glfwWindowShouldClose ( window ) ) {
float ratio ;
glm : : mat4 model , view , projection , mvp ;
int width = 0 ;
int height = 0 ;
glfwGetFramebufferSize ( window , & width , & height ) ;
height = height = = 0 ? 1 : height ;
ratio = width / ( float ) height ;
glViewport ( 0 , 0 , width , height ) ;
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glClearColor ( 49.f / 255 , 77.f / 255 , 121.f / 255 , 1.f ) ;
view = glm : : lookAt ( glm : : vec3 ( 0 , 0 , 10 ) , glm : : vec3 ( 0 , 0 , 0 ) , glm : : vec3 ( 0 , 1 , 0 ) ) ;
projection = glm : : perspective ( glm : : radians ( 60.f ) , ratio , 1.f , 1000.f ) ;
2024-12-02 15:01:10 +00:00
ImageBuffer : : Get ( ) - > Update ( ImageBuffer : : IBType : : Human , & huaman ) ;
2024-11-30 14:26:28 +00:00
glBindVertexArray ( VAO ) ;
2024-12-01 17:31:51 +00:00
shader . use ( ) ;
background . Active ( 0 ) ;
huaman . Active ( 1 ) ;
2024-11-30 14:26:28 +00:00
glDrawElements ( GL_TRIANGLES , 6 , GL_UNSIGNED_INT , 0 ) ;
glfwSwapBuffers ( window ) ;
glfwPollEvents ( ) ;
}
glBindVertexArray ( VAO ) ; // seeing as we only have a single VAO there's no need to bind it every time, but we'll do so to keep things a bit more organized
//glDrawArrays(GL_TRIANGLES, 0, 6);
2024-12-01 17:31:51 +00:00
//glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
2024-11-30 14:26:28 +00:00
glfwDestroyWindow ( window ) ;
glfwTerminate ( ) ;
2024-12-01 17:31:51 +00:00
ImageBuffer : : Shotdown ( ) ;
2024-11-30 14:26:28 +00:00
IpcMoudle : : Shotdown ( ) ;
Logger : : Shotdown ( ) ;
return 0 ;
}
# endif