Skip to content
Snippets Groups Projects
Commit b3eec7d4 authored by Woohyung Choi's avatar Woohyung Choi
Browse files

apply image formats.

make materials.
parent ea8cb72f
Branches
No related tags found
No related merge requests found
......@@ -418,6 +418,14 @@ GLuint load_image(const std::string fileName)
Image *tex = load_Image(fileName, &width, &height, &nrChannels);
if (tex != NULL && tex->getData() != NULL)
{
GLenum format;
if (nrChannels == 1)
format = GL_RED;
else if (nrChannels == 3)
format = GL_RGB;
else if (nrChannels == 4)
format = GL_RGBA;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
......@@ -427,7 +435,7 @@ GLuint load_image(const std::string fileName)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex->getData());
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, tex->getData());
glGenerateMipmap(GL_TEXTURE_2D);
}
......
......@@ -70,7 +70,8 @@ int main()
auto container_specular = load_image("container2_specular.png");
auto defaultMaterial = new Material(lightmap, orange, transparent);
auto planeMaterial = new Material(lightmap, container_diffuse, transparent);
auto cubeMaterial = new Material(lightmap, container_diffuse, container_specular);
auto planeMaterial = new Material(lightmap, magenta, white);
auto teapot = make_render_object(make_mesh("teapot.obj"));
{
......@@ -88,7 +89,7 @@ int main()
cube1->set_scale(glm::vec3(10, 10, 4));
}
{
cube1->set_material(defaultMaterial);
cube1->set_material(cubeMaterial);
}
auto cube2 = make_render_object(cube);
......@@ -98,7 +99,7 @@ int main()
cube2->set_scale(glm::vec3(12, 12, 1));
}
{
cube2->set_material(defaultMaterial);
cube2->set_material(cubeMaterial);
}
auto plane = make_render_object(make_mesh("plane.obj"));
......@@ -106,7 +107,7 @@ int main()
plane->set_scale(glm::vec3(10, 10, 1));
}
{
plane->set_material(defaultMaterial);
plane->set_material(planeMaterial);
}
auto cube3 = make_render_object(cube);
......@@ -116,7 +117,7 @@ int main()
cube3->set_scale(glm::vec3(50, 50, 0.5));
}
{
cube3->set_material(defaultMaterial);
cube3->set_material(cubeMaterial);
}
while (!glfwWindowShouldClose(window))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment