progress
This commit is contained in:
parent
48c90cd5bf
commit
e9b1c32974
@ -5,10 +5,9 @@ out vec4 FragColor;
|
|||||||
in vec3 ourColor;
|
in vec3 ourColor;
|
||||||
in vec2 TexCoord;
|
in vec2 TexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture1;
|
uniform sampler2D tex;
|
||||||
uniform sampler2D texture2;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = texture(texture2, TexCoord);
|
FragColor = texture(tex, TexCoord);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
BIN
build/untap
BIN
build/untap
Binary file not shown.
43
src/main.cpp
43
src/main.cpp
@ -39,17 +39,21 @@ int main()
|
|||||||
Shader myShader("shaders/shader.vs", "shaders/shader.fs");
|
Shader myShader("shaders/shader.vs", "shaders/shader.fs");
|
||||||
|
|
||||||
texture_t tex;
|
texture_t tex;
|
||||||
tex.data = stbi_load("textures/container.jpg", &tex.width, &tex.height, &tex.nrChannels, 0);
|
|
||||||
|
|
||||||
unsigned int texture1;
|
stbi_set_flip_vertically_on_load(true);
|
||||||
glGenTextures(1, &texture1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture1);
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
tex.data = stbi_load("textures/wg.jpg", &tex.width, &tex.height, &tex.nrChannels, 0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
|
unsigned int texture;
|
||||||
|
glGenTextures(1, &texture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
if (tex.data) {
|
if (tex.data) {
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex.data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex.data);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
@ -57,30 +61,10 @@ int main()
|
|||||||
std::cout << "Failed to load texture\n";
|
std::cout << "Failed to load texture\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
stbi_image_free(tex.data);
|
|
||||||
|
|
||||||
stbi_set_flip_vertically_on_load(true);
|
|
||||||
tex.data = stbi_load("textures/wg.jpg", &tex.width, &tex.height, &tex.nrChannels, 0);
|
|
||||||
|
|
||||||
unsigned int texture2;
|
|
||||||
glGenTextures(1, &texture2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture2);
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
|
|
||||||
if (tex.data) {
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data);
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
} else {
|
|
||||||
std::cout << "Failed to load texture\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
stbi_image_free(tex.data);
|
stbi_image_free(tex.data);
|
||||||
|
|
||||||
|
|
||||||
unsigned int VAO;
|
unsigned int VAO;
|
||||||
glGenVertexArrays(1, &VAO);
|
glGenVertexArrays(1, &VAO);
|
||||||
|
|
||||||
@ -110,8 +94,7 @@ int main()
|
|||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
|
|
||||||
myShader.use();
|
myShader.use();
|
||||||
myShader.setInt("texture1", 0);
|
myShader.setInt("tex", 0);
|
||||||
myShader.setInt("texture2", 1);
|
|
||||||
|
|
||||||
|
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
@ -125,9 +108,7 @@ int main()
|
|||||||
myShader.use();
|
myShader.use();
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture1);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture2);
|
|
||||||
|
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
@ -5,10 +5,9 @@ out vec4 FragColor;
|
|||||||
in vec3 ourColor;
|
in vec3 ourColor;
|
||||||
in vec2 TexCoord;
|
in vec2 TexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture1;
|
uniform sampler2D tex;
|
||||||
uniform sampler2D texture2;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = texture(texture2, TexCoord);
|
FragColor = texture(tex, TexCoord);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user