added texture class, changed shader extension names
This commit is contained in:
parent
95be5f081e
commit
6fb3ffcfed
5 changed files with 58 additions and 53 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <stb_image/stb_image.h>
|
||||
|
||||
#include <shader.h>
|
||||
#include <texture.h>
|
||||
|
||||
const int SCREEN_WIDTH = 800;
|
||||
const int SCREEN_HEIGHT = 600;
|
||||
|
|
@ -71,7 +72,7 @@ int main(int argc, char* argv[])
|
|||
glfwSetFramebufferSizeCallback(window, window_resize_callback);
|
||||
|
||||
// Load Shader
|
||||
Shader shaderTest("shaders/basicVertex.vs", "shaders/basicFragment.fs");
|
||||
Shader shaderTest("shaders/basicVertex.vert", "shaders/basicFragment.frag");
|
||||
float vertices[] = {
|
||||
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
|
||||
|
|
@ -112,56 +113,12 @@ int main(int argc, char* argv[])
|
|||
glEnableVertexAttribArray(2);
|
||||
|
||||
|
||||
unsigned int texture1, texture2;
|
||||
glGenTextures(1, &texture1);
|
||||
glBindTexture(GL_TEXTURE_2D, texture1);
|
||||
// set the texture wrapping/filtering options (on the currently bound texture object)
|
||||
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_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// load and generate the texture
|
||||
int width, height, nrChannels;
|
||||
unsigned char *data = stbi_load("placeholders/wall.jpg", &width, &height, &nrChannels, 0);
|
||||
if (data)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to load texture" << std::endl;
|
||||
}
|
||||
stbi_image_free(data);
|
||||
|
||||
// texture 2
|
||||
// ---------
|
||||
glGenTextures(1, &texture2);
|
||||
glBindTexture(GL_TEXTURE_2D, texture2);
|
||||
// set the texture wrapping parameters
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
// set texture filtering parameters
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// load image, create texture and generate mipmaps
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
data = stbi_load("placeholders/awesomeface.png", &width, &height, &nrChannels, 0);
|
||||
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
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to load texture" << std::endl;
|
||||
}
|
||||
stbi_image_free(data);
|
||||
Texture texture1("placeholders/wall.jpg");
|
||||
Texture texture2("placeholders/awesomeface.png", true);
|
||||
|
||||
shaderTest.Use(); // don't forget to activate/use the shader before setting uniforms!
|
||||
shaderTest.setInt("ourTexture", 0);
|
||||
shaderTest.setInt("decal", 1);
|
||||
shaderTest.setInt("ourTexture", texture1.ID);
|
||||
shaderTest.setInt("decal", texture2.ID);
|
||||
|
||||
// Render Loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
|
|
@ -176,9 +133,9 @@ int main(int argc, char* argv[])
|
|||
shaderTest.Use();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture1);
|
||||
glBindTexture(GL_TEXTURE_2D, texture1.ID);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, texture2);
|
||||
glBindTexture(GL_TEXTURE_2D, texture2.ID);
|
||||
|
||||
// Draw our triangle
|
||||
glBindVertexArray(VAO);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue