let there be textures
This commit is contained in:
parent
56daae2c9e
commit
66c96af62a
@ -65,6 +65,8 @@ GLuint LinkShader(GLuint vertexShader, GLuint fragmentShader){
|
|||||||
glGetProgramInfoLog(shaderProgram, 512, NULL, buffer);
|
glGetProgramInfoLog(shaderProgram, 512, NULL, buffer);
|
||||||
printf("%s", buffer);
|
printf("%s", buffer);
|
||||||
|
|
||||||
|
glUseProgram(shaderProgram);
|
||||||
|
|
||||||
return shaderProgram;
|
return shaderProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,28 +122,36 @@ int main(void)
|
|||||||
GLuint tex[2];
|
GLuint tex[2];
|
||||||
glGenTextures(2, tex);
|
glGenTextures(2, tex);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tex[0]);
|
|
||||||
|
|
||||||
//Load image
|
//Load image
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex[0]);
|
||||||
image = stbi_load("./sample.png", &width, &height, NULL, 3);
|
image = stbi_load("./sample.png", &width, &height, NULL, 3);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||||
stbi_image_free(image);
|
stbi_image_free(image);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(shaderProgram, "kitty"), 0);
|
glUniform1i(glGetUniformLocation(shaderProgram, "kitty"), 0);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex[1]);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Load image
|
//Load image
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex[1]);
|
||||||
image2 = stbi_load("./sample2.png", &width, &height, NULL, 3);
|
image2 = stbi_load("./sample2.png", &width, &height, NULL, 3);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image2);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image2);
|
||||||
stbi_image_free(image2);
|
stbi_image_free(image2);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(shaderProgram, "puppy"), 1);
|
glUniform1i(glGetUniformLocation(shaderProgram, "puppy"), 1);
|
||||||
|
|
||||||
|
/* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); */
|
||||||
|
/* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); */
|
||||||
|
/* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); */
|
||||||
|
/* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); */
|
||||||
|
|
||||||
GLint posAttrib = glGetAttribLocation(shaderProgram, "positions");
|
GLint posAttrib = glGetAttribLocation(shaderProgram, "positions");
|
||||||
glEnableVertexAttribArray(posAttrib);
|
glEnableVertexAttribArray(posAttrib);
|
||||||
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 7, 0);
|
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 7, 0);
|
||||||
@ -154,7 +164,6 @@ int main(void)
|
|||||||
glEnableVertexAttribArray(texCoordsAttrib);
|
glEnableVertexAttribArray(texCoordsAttrib);
|
||||||
glVertexAttribPointer(texCoordsAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 7, (void*)(5*sizeof(float)));
|
glVertexAttribPointer(texCoordsAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 7, (void*)(5*sizeof(float)));
|
||||||
|
|
||||||
glUseProgram(shaderProgram);
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
bool should_close = false;
|
bool should_close = false;
|
||||||
|
@ -13,7 +13,7 @@ out vec4 outColor;
|
|||||||
void main(){
|
void main(){
|
||||||
vec4 kit = texture(kitty, TexCoords);
|
vec4 kit = texture(kitty, TexCoords);
|
||||||
vec4 pup = texture(puppy, TexCoords);
|
vec4 pup = texture(puppy, TexCoords);
|
||||||
outColor = pup;
|
outColor = mix(kit, pup, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ft=glsl: */
|
/* vim: set ft=glsl: */
|
||||||
|
Loading…
Reference in New Issue
Block a user