@ -1,24 +1,10 @@
# include " glew.h "
//#include "imgui.h"
//#include "imgui_impl_glfw.h"
//#include "imgui_impl_opengl3.h"
//#include <stdio.h>
//#define GL_SILENCE_DEPRECATION
//#if defined(IMGUI_IMPL_OPENGL_ES2)
//#include <GLES2/gl2.h>
//#endif
# include <GLFW/glfw3.h>
# include "glm.hpp"
# include "ext.hpp"
# include <iostream>
# include <cmath>
//#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
//#pragma comment(lib, "legacy_stdio_definitions")
//#endif
# include "Shader_Loader.h"
# include "Render_Utils.h"
# include "Texture.h"
@ -33,17 +19,10 @@ namespace texture {
GLuint earth ;
GLuint clouds ;
GLuint moon ;
GLuint ship ;
GLuint mercury ;
GLuint venus ;
GLuint mars ;
GLuint sun ;
GLuint grid ;
GLuint earthNormal ;
GLuint asteroidNormal ;
GLuint shipNormal ;
}
GLuint program ;
@ -53,7 +32,6 @@ GLuint programTex;
Core : : Shader_Loader shaderLoader ;
//Core::RenderContext shipContext;
Core : : RenderContext sphereContext ;
glm : : vec3 sunPosition = glm : : vec3 ( 12.f , 0.f , 12.f ) ;
@ -70,30 +48,11 @@ unsigned int colorBuffers[2];
unsigned int depthMap ;
unsigned int depthMapFBO ;
int HDR_WIDTH = 1024 ;
int HDR_HEIGHT = 1024 ;
glm : : vec3 lightColor = glm : : vec3 ( 50 , 50 , 50 ) ;
/*
glm : : mat4 createShipMatrix ( )
{
glm : : vec3 cameraSide = glm : : normalize ( glm : : cross ( cameraDir , glm : : vec3 ( 0.f , 1.f , 0.f ) ) ) ;
glm : : vec3 cameraUp = glm : : normalize ( glm : : cross ( cameraSide , cameraDir ) ) ;
glm : : mat4 shipRotationMatrix = glm : : mat4 ( {
cameraSide . x , cameraSide . y , cameraSide . z , 0 ,
cameraUp . x , cameraUp . y , cameraUp . z , 0 ,
shipDir . x , shipDir . y , shipDir . z , 0 ,
0. , 0. , 0. , 1. ,
} ) ;
shipRotationMatrix = glm : : transpose ( shipRotationMatrix ) ;
return shipRotationMatrix ;
}
*/
glm : : mat4 createCameraMatrix ( )
{
glm : : vec3 cameraSide = glm : : normalize ( glm : : cross ( cameraDir , glm : : vec3 ( 0.f , 1.f , 0.f ) ) ) ;
@ -202,18 +161,6 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture
glUseProgram ( 0 ) ;
}
/*
void drawObjectColor ( Core : : RenderContext & context , glm : : mat4 modelMatrix , glm : : vec3 color ) {
glUseProgram ( program ) ;
glUniform3f ( glGetUniformLocation ( program , " color " ) , color . x , color . y , color . z ) ;
glm : : mat4 viewProjectionMatrix = createPerspectiveMatrix ( ) * createCameraMatrix ( ) ;
glm : : mat4 transformation = viewProjectionMatrix * modelMatrix ;
glUniformMatrix4fv ( glGetUniformLocation ( program , " transformation " ) , 1 , GL_FALSE , ( float * ) & transformation ) ;
glUniformMatrix4fv ( glGetUniformLocation ( program , " modelMatrix " ) , 1 , GL_FALSE , ( float * ) & modelMatrix ) ;
Core : : DrawContext ( context ) ;
glUseProgram ( 0 ) ;
}
void drawObjectPBR ( Core : : RenderContext & context , glm : : mat4 modelMatrix , glm : : vec3 color , float roughness , float metallic ) {
glm : : mat4 viewProjectionMatrix = createPerspectiveMatrix ( ) * createCameraMatrix ( ) ;
@ -244,7 +191,6 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
}
*/
void renderScene ( GLFWwindow * window )
{
glClearColor ( 0.0f , 0.0f , 0.15f , 1.0f ) ;
@ -252,58 +198,6 @@ void renderScene(GLFWwindow* window)
glm : : mat4 transformation ;
float time = glfwGetTime ( ) ;
/*
glm : : mat4 mercuryScale = glm : : scale ( glm : : vec3 ( 0.24 ) ) ;
glm : : mat4 mercuryRotate = glm : : rotate ( time * 0.24f , glm : : vec3 ( 0 , 1 , 0 ) ) ;
glm : : mat4 mercuryTranslate = glm : : translate ( glm : : vec3 ( 0 , 0 , - 3 ) ) ;
glm : : mat4 venusScale = glm : : scale ( glm : : vec3 ( 0.55 ) ) ;
glm : : mat4 venusRotate = glm : : rotate ( time * 0.61f , glm : : vec3 ( 0 , 1 , 0 ) ) ;
glm : : mat4 venusTranslate = glm : : translate ( glm : : vec3 ( 0 , 0 , - 5 ) ) ;
glm : : mat4 earthScale = glm : : scale ( glm : : vec3 ( 0.6 ) ) ;
glm : : mat4 earthRotate = glm : : rotate ( time , glm : : vec3 ( 0 , 1 , 0 ) ) ;
glm : : mat4 earthTranslate = glm : : translate ( glm : : vec3 ( 0 , 0 , - 7 ) ) ;
glm : : mat4 moonScale = glm : : scale ( glm : : vec3 ( 0.2 ) ) ;
glm : : mat4 moonRotate = glm : : rotate ( time , glm : : vec3 ( 0 , 1 , 0 ) ) ;
glm : : mat4 moonTranslate = glm : : translate ( glm : : vec3 ( 0 , 0 , - 2 ) ) ;
glm : : mat4 marsScale = glm : : scale ( glm : : vec3 ( 0.3 ) ) ;
glm : : mat4 marsRotate = glm : : rotate ( time * 1.8f , glm : : vec3 ( 0 , 1 , 0 ) ) ;
glm : : mat4 marsTranslate = glm : : translate ( glm : : vec3 ( 0 , 0 , - 9 ) ) ;
//glm::mat4 shipScale = glm::scale(glm::vec3(0.3));
//glm::mat4 shipRotate = createShipMatrix();
//glm::mat4 shipTranslate = glm::translate(shipPos);
//glUseProgram(program);
//glUniform3f(glGetUniformLocation(program, "lightDir"), 1.0, -1.0, 0.0);
//glUniform3f(glGetUniformLocation(program, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
//glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
//glUniform3f(glGetUniformLocation(program, "lightPos"), 0.0, 0.0, 0.0);
//glUseProgram(0);
drawObjectColor ( sphereContext , sunScale , glm : : vec3 ( 0.9 , 0.9 , 0.2 ) ) ; //sun
drawObjectTexture ( sphereContext , mercuryRotate * mercuryTranslate * mercuryScale , texture : : mercury ) ; //mercury
drawObjectTexture ( sphereContext , venusRotate * venusTranslate * venusScale , texture : : venus ) ; //venus
drawObjectTexture ( sphereContext , earthRotate * earthTranslate * earthScale , texture : : earth ) ; //earth
drawObjectTexture ( sphereContext , earthRotate * earthTranslate * earthScale * moonRotate * moonTranslate * moonScale , texture : : moon ) ; //moon
drawObjectTexture ( sphereContext , marsRotate * marsTranslate * marsScale , texture : : mars ) ; //mars
drawObjectTexture ( shipContext , shipTranslate * shipRotate * shipScale , texture : : ship ) ; //ship
*/
//glUseProgram(programTex);
//glUniform3f(glGetUniformLocation(programTex, "lightDir"), cameraDir.x, cameraDir.y, cameraDir.z);
//glUseProgram(0);
glm : : mat4 sunScale = glm : : scale ( glm : : vec3 ( 0.04f ) ) ;
glm : : mat4 sunTranslate = glm : : translate ( sunPosition ) ;
@ -347,7 +241,6 @@ void init(GLFWwindow* window)
initHDR ( ) ;
programDepth = shaderLoader . CreateProgram ( " shaders/shader_smap.vert " , " shaders/shader_smap.frag " ) ;
program = shaderLoader . CreateProgram ( " shaders/shader.vert " , " shaders/shader.frag " ) ;
programTex = shaderLoader . CreateProgram ( " shaders/shader_tex.vert " , " shaders/shader_tex.frag " ) ;
programSun = shaderLoader . CreateProgram ( " shaders/shader_sun.vert " , " shaders/shader_sun.frag " ) ;
@ -360,7 +253,9 @@ void init(GLFWwindow* window)
void shutdown ( GLFWwindow * window )
{
shaderLoader . DeleteProgram ( program ) ;
shaderLoader . DeleteProgram ( programDepth ) ;
shaderLoader . DeleteProgram ( programTex ) ;
shaderLoader . DeleteProgram ( programSun ) ;
}
//obsluga wejscia
@ -368,8 +263,8 @@ void processInput(GLFWwindow* window)
{
glm : : vec3 cameraSide = glm : : normalize ( glm : : cross ( cameraDir , glm : : vec3 ( 0.f , 1.f , 0.f ) ) ) ;
float angleSpeed = 0.0 2f;
float moveSpeed = 0.0 4f;
float angleSpeed = 0.0 0 2f;
float moveSpeed = 0.0 0 4f;
if ( glfwGetKey ( window , GLFW_KEY_ESCAPE ) = = GLFW_PRESS ) {
glfwSetWindowShouldClose ( window , true ) ;
@ -378,107 +273,24 @@ void processInput(GLFWwindow* window)
cameraPos + = cameraDir * moveSpeed ;
if ( glfwGetKey ( window , GLFW_KEY_S ) = = GLFW_PRESS )
cameraPos - = cameraDir * moveSpeed ;
if ( glfwGetKey ( window , GLFW_KEY_X ) = = GLFW_PRESS )
cameraPos + = cameraSide * moveSpeed ;
if ( glfwGetKey ( window , GLFW_KEY_Z ) = = GLFW_PRESS )
cameraPos - = cameraSide * moveSpeed ;
if ( glfwGetKey ( window , GLFW_KEY_A ) = = GLFW_PRESS )
cameraDir = glm : : vec3 ( glm : : eulerAngleY ( angleSpeed ) * glm : : vec4 ( cameraDir , 0 ) ) ;
if ( glfwGetKey ( window , GLFW_KEY_D ) = = GLFW_PRESS )
cameraDir = glm : : vec3 ( glm : : eulerAngleY ( - angleSpeed ) * glm : : vec4 ( cameraDir , 0 ) ) ;
//shipPos = cameraPos + 0.75 * cameraDir + glm::vec3(0, -0.25f, 0);
//shipDir = cameraDir;
cameraPos + = cameraSide * moveSpeed ;
if ( glfwGetKey ( window , GLFW_KEY_A ) = = GLFW_PRESS )
cameraPos - = cameraSide * moveSpeed ;
//if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
// cameraDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(cameraDir, 0));
//if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
// cameraDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(cameraDir, 0));
//cameraDir = glm::normalize(-cameraPos);
cameraDir = glm : : normalize ( - cameraPos ) ;
}
// Our state
//bool show_demo_window = true;
//bool show_another_window = false;
//ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// funkcja jest glowna petla
void renderLoop ( GLFWwindow * window ) {
// Setup Dear ImGui context
//IMGUI_CHECKVERSION();
//ImGui::CreateContext();
//ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
// Setup Dear ImGui style
//ImGui::StyleColorsDark();
while ( ! glfwWindowShouldClose ( window ) )
{
/*glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame ( ) ;
ImGui_ImplGlfw_NewFrame ( ) ;
ImGui : : NewFrame ( ) ;
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
if ( show_demo_window )
ImGui : : ShowDemoWindow ( & show_demo_window ) ;
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
{
static float f = 0.0f ;
static int counter = 0 ;
ImGui : : Begin ( " Hello, world! " ) ; // Create a window called "Hello, world!" and append into it.
ImGui : : Text ( " This is some useful text. " ) ; // Display some text (you can use a format strings too)
ImGui : : Checkbox ( " Demo Window " , & show_demo_window ) ; // Edit bools storing our window open/close state
ImGui : : Checkbox ( " Another Window " , & show_another_window ) ;
ImGui : : SliderFloat ( " float " , & f , 0.0f , 1.0f ) ; // Edit 1 float using a slider from 0.0f to 1.0f
ImGui : : ColorEdit3 ( " clear color " , ( float * ) & clear_color ) ; // Edit 3 floats representing a color
if ( ImGui : : Button ( " Button " ) ) // Buttons return true when clicked (most widgets return true when edited/activated)
counter + + ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( " counter = %d " , counter ) ;
ImGui : : Text ( " Application average %.3f ms/frame (%.1f FPS) " , 1000.0f / io . Framerate , io . Framerate ) ;
ImGui : : End ( ) ;
}
// 3. Show another simple window.
if ( show_another_window )
{
ImGui : : Begin ( " Another Window " , & show_another_window ) ; // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui : : Text ( " Hello from another window! " ) ;
if ( ImGui : : Button ( " Close Me " ) )
show_another_window = false ;
ImGui : : End ( ) ;
}
// Rendering
ImGui : : Render ( ) ;
int display_w , display_h ;
glfwGetFramebufferSize ( window , & display_w , & display_h ) ;
glViewport ( 0 , 0 , display_w , display_h ) ;
glClearColor ( clear_color . x * clear_color . w , clear_color . y * clear_color . w , clear_color . z * clear_color . w , clear_color . w ) ;
glClear ( GL_COLOR_BUFFER_BIT ) ;
ImGui_ImplOpenGL3_RenderDrawData ( ImGui : : GetDrawData ( ) ) ;
glfwSwapBuffers ( window ) ;
*/
processInput ( window ) ;
renderScene ( window ) ;
glfwPollEvents ( ) ;
}
/*
// Cleanup
ImGui_ImplOpenGL3_Shutdown ( ) ;
ImGui_ImplGlfw_Shutdown ( ) ;
ImGui : : DestroyContext ( ) ;
glfwDestroyWindow ( window ) ;
glfwTerminate ( ) ;
return 0 ; */
}
//}