Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GLuint texture = 0;
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
- glGenFramebuffers(1, &targetFBO);
- glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
- - (void) draw {
- GLfloat textureCoordinates[] = {
- 0.0f, 0.0f,
- 1.0f, 0.0f,
- 0.0f, 1.0f,
- 1.0f, 1.0f,
- };
- GLfloat imageVertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- -1.0f, 1.0f,
- 1.0f, 1.0f,
- };
- glViewport(0, 0, targetWidth, targetHeight);
- glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
- glUseProgram(program);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, textureID);
- glUniform1i(inputTextureLocation, 2);
- glDisable(GL_BLEND);
- glVertexAttribPointer(positionLocation, 2, GL_FLOAT, 0, 0, imageVertices);
- glVertexAttribPointer(inputTextureCoordinateLocation, 2, GL_FLOAT, 0, 0, textureCoordinates);
- // Clear the screen
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- }
- attribute vec4 position;
- attribute vec4 inputTextureCoordinate;
- varying vec2 textureCoordinate;
- void main()
- {
- gl_Position = position;
- textureCoordinate = inputTextureCoordinate.xy;
- }
- varying highp vec2 textureCoordinate;
- uniform sampler2D inputTexture;
- void main()
- {
- gl_FragColor = texture2D(inputTexture, textureCoordinate);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement