mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-12 03:23:22 +08:00
Getting started content code-rework updates.
This commit is contained in:
@@ -37,7 +37,7 @@ public:
|
|||||||
vShaderFile.close();
|
vShaderFile.close();
|
||||||
fShaderFile.close();
|
fShaderFile.close();
|
||||||
// convert stream into string
|
// convert stream into string
|
||||||
vertexCode = vShaderStream.str();
|
vertexCode = vShaderStream.str();
|
||||||
fragmentCode = fShaderStream.str();
|
fragmentCode = fShaderStream.str();
|
||||||
}
|
}
|
||||||
catch (std::ifstream::failure e)
|
catch (std::ifstream::failure e)
|
||||||
@@ -96,10 +96,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
// utility function for checking shader compilation/linking errors.
|
// utility function for checking shader compilation/linking errors.
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void checkCompileErrors(GLuint shader, std::string type)
|
void checkCompileErrors(unsigned int shader, std::string type)
|
||||||
{
|
{
|
||||||
GLint success;
|
int success;
|
||||||
GLchar infoLog[1024];
|
char infoLog[1024];
|
||||||
if (type != "PROGRAM")
|
if (type != "PROGRAM")
|
||||||
{
|
{
|
||||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
@@ -18,14 +22,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
@@ -18,14 +22,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
const char *vertexShaderSource = "#version 330 core\n"
|
const char *vertexShaderSource = "#version 330 core\n"
|
||||||
"layout (location = 0) in vec3 aPos;\n"
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
@@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n"
|
|||||||
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||||
"}\0";
|
"}\0";
|
||||||
const char *fragmentShaderSource = "#version 330 core\n"
|
const char *fragmentShaderSource = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -31,14 +35,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
const char *vertexShaderSource = "#version 330 core\n"
|
const char *vertexShaderSource = "#version 330 core\n"
|
||||||
"layout (location = 0) in vec3 aPos;\n"
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
@@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n"
|
|||||||
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||||
"}\0";
|
"}\0";
|
||||||
const char *fragmentShaderSource = "#version 330 core\n"
|
const char *fragmentShaderSource = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -31,14 +35,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
const char *vertexShaderSource = "#version 330 core\n"
|
const char *vertexShaderSource = "#version 330 core\n"
|
||||||
"layout (location = 0) in vec3 aPos;\n"
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
@@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n"
|
|||||||
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||||
"}\0";
|
"}\0";
|
||||||
const char *fragmentShaderSource = "#version 330 core\n"
|
const char *fragmentShaderSource = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -31,14 +35,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
const char *vertexShaderSource = "#version 330 core\n"
|
const char *vertexShaderSource = "#version 330 core\n"
|
||||||
"layout (location = 0) in vec3 aPos;\n"
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
@@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n"
|
|||||||
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||||
"}\0";
|
"}\0";
|
||||||
const char *fragmentShaderSource = "#version 330 core\n"
|
const char *fragmentShaderSource = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -31,14 +35,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
const char *vertexShaderSource = "#version 330 core\n"
|
const char *vertexShaderSource = "#version 330 core\n"
|
||||||
"layout (location = 0) in vec3 aPos;\n"
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
@@ -13,16 +17,16 @@ const char *vertexShaderSource = "#version 330 core\n"
|
|||||||
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||||
"}\0";
|
"}\0";
|
||||||
const char *fragmentShader1Source = "#version 330 core\n"
|
const char *fragmentShader1Source = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
const char *fragmentShader2Source = "#version 330 core\n"
|
const char *fragmentShader2Source = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);\n"
|
" FragColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
|
|
||||||
|
|
||||||
@@ -38,14 +42,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
const char *vertexShaderSource ="#version 330 core\n"
|
const char *vertexShaderSource ="#version 330 core\n"
|
||||||
"layout (location = 0) in vec3 aPos;\n"
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
@@ -14,11 +18,11 @@ const char *vertexShaderSource ="#version 330 core\n"
|
|||||||
"}\0";
|
"}\0";
|
||||||
|
|
||||||
const char *fragmentShaderSource = "#version 330 core\n"
|
const char *fragmentShaderSource = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"uniform vec4 ourColor;\n"
|
"uniform vec4 ourColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = ourColor;\n"
|
" FragColor = ourColor;\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -34,13 +38,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -51,7 +55,6 @@ int main()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// build and compile our shader program
|
// build and compile our shader program
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// vertex shader
|
// vertex shader
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
const char *vertexShaderSource ="#version 330 core\n"
|
const char *vertexShaderSource ="#version 330 core\n"
|
||||||
"layout (location = 0) in vec3 aPos;\n"
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
"layout (location = 1) in vec3 aColor;\n"
|
"layout (location = 1) in vec3 aColor;\n"
|
||||||
@@ -17,11 +21,11 @@ const char *vertexShaderSource ="#version 330 core\n"
|
|||||||
"}\0";
|
"}\0";
|
||||||
|
|
||||||
const char *fragmentShaderSource = "#version 330 core\n"
|
const char *fragmentShaderSource = "#version 330 core\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"in vec3 ourColor;\n"
|
"in vec3 ourColor;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fragColor = vec4(ourColor, 1.0f);\n"
|
" FragColor = vec4(ourColor, 1.0f);\n"
|
||||||
"}\n\0";
|
"}\n\0";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -36,14 +40,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -54,7 +58,6 @@ int main()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// build and compile our shader program
|
// build and compile our shader program
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// vertex shader
|
// vertex shader
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 fragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
in vec3 ourColor;
|
in vec3 ourColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fragColor = vec4(ourColor, 1.0f);
|
FragColor = vec4(ourColor, 1.0f);
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,6 @@ out vec3 ourColor;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(aPos, 1.0f);
|
gl_Position = vec4(aPos, 1.0);
|
||||||
ourColor = aColor;
|
ourColor = aColor;
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
@@ -20,14 +24,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -38,7 +42,6 @@ int main()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// build and compile our shader program
|
// build and compile our shader program
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader ourShader("3.3.shader.vs", "3.3.shader.fs"); // you can name your shader files however you like
|
Shader ourShader("3.3.shader.vs", "3.3.shader.fs"); // you can name your shader files however you like
|
||||||
@@ -50,7 +53,6 @@ int main()
|
|||||||
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right
|
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right
|
||||||
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
|
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
|
||||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top
|
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int VBO, VAO;
|
unsigned int VBO, VAO;
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
@@ -22,14 +26,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -93,8 +97,8 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
int width, height, nrComponents;
|
int width, height, nrChannels;
|
||||||
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0);
|
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
@@ -22,14 +26,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -95,9 +99,9 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
int width, height, nrComponents;
|
int width, height, nrChannels;
|
||||||
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
||||||
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0);
|
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
@@ -119,7 +123,7 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrComponents, 0);
|
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
@@ -22,14 +26,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -40,7 +44,6 @@ int main()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader ourShader("4.2.texture_combined.vs", "4.2.texture_combined.fs");
|
Shader ourShader("4.2.texture_combined.vs", "4.2.texture_combined.fs");
|
||||||
@@ -96,9 +99,9 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
int width, height, nrComponents;
|
int width, height, nrChannels;
|
||||||
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
||||||
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0);
|
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
@@ -120,7 +123,7 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrComponents, 0);
|
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
||||||
@@ -142,7 +145,6 @@ int main()
|
|||||||
ourShader.setInt("texture2", 1);
|
ourShader.setInt("texture2", 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// render loop
|
// render loop
|
||||||
// -----------
|
// -----------
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
@@ -22,14 +26,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -40,7 +44,6 @@ int main()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader ourShader("4.2.texture_combined.vs", "4.2.texture_combined.fs");
|
Shader ourShader("4.2.texture_combined.vs", "4.2.texture_combined.fs");
|
||||||
@@ -49,8 +52,8 @@ int main()
|
|||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
float vertices[] = {
|
float vertices[] = {
|
||||||
// positions // colors // texture coords (note that we changed them to 'zoom in' on our texture image)
|
// positions // colors // texture coords (note that we changed them to 'zoom in' on our texture image)
|
||||||
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.55f, 0.55f, // top right
|
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.55f, 0.55f, // top right
|
||||||
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.55f, 0.45f, // bottom right
|
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.55f, 0.45f, // bottom right
|
||||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.45f, 0.45f, // bottom left
|
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.45f, 0.45f, // bottom left
|
||||||
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.45f, 0.55f // top left
|
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.45f, 0.55f // top left
|
||||||
};
|
};
|
||||||
@@ -96,9 +99,9 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // set texture filtering to nearest neighbor to clearly see the texels/pixels
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // set texture filtering to nearest neighbor to clearly see the texels/pixels
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
int width, height, nrComponents;
|
int width, height, nrChannels;
|
||||||
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
||||||
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0);
|
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
@@ -120,7 +123,7 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // set texture filtering to nearest neighbor to clearly see the texels/pixels
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // set texture filtering to nearest neighbor to clearly see the texels/pixels
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrComponents, 0);
|
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
||||||
@@ -136,13 +139,12 @@ int main()
|
|||||||
// tell opengl for each sampler to which texture unit it belongs to (only has to be done once)
|
// tell opengl for each sampler to which texture unit it belongs to (only has to be done once)
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
ourShader.use(); // don't forget to activate/use the shader before setting uniforms!
|
ourShader.use(); // don't forget to activate/use the shader before setting uniforms!
|
||||||
// either set it manually like so:
|
// either set it manually like so:
|
||||||
glUniform1i(glGetUniformLocation(ourShader.ID, "texture1"), 0);
|
glUniform1i(glGetUniformLocation(ourShader.ID, "texture1"), 0);
|
||||||
// or set it via the texture class
|
// or set it via the texture class
|
||||||
ourShader.setInt("texture2", 1);
|
ourShader.setInt("texture2", 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// render loop
|
// render loop
|
||||||
// -----------
|
// -----------
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 1280;
|
||||||
|
const unsigned int SCR_HEIGHT = 720;
|
||||||
|
|
||||||
// stores how much we're seeing of either texture
|
// stores how much we're seeing of either texture
|
||||||
float mixValue = 0.2f;
|
float mixValue = 0.2f;
|
||||||
|
|
||||||
@@ -25,14 +29,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
// glad: load all OpenGL function pointers
|
// glad: load all OpenGL function pointers
|
||||||
@@ -99,9 +103,9 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
int width, height, nrComponents;
|
int width, height, nrChannels;
|
||||||
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis.
|
||||||
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0);
|
unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
@@ -123,7 +127,7 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrComponents, 0);
|
data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrChannels, 0);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
|
||||||
@@ -145,7 +149,6 @@ int main()
|
|||||||
ourShader.setInt("texture2", 1);
|
ourShader.setInt("texture2", 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// render loop
|
// render loop
|
||||||
// -----------
|
// -----------
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
|||||||
Reference in New Issue
Block a user