Editing pixel of a texture

Started by
11 comments, last by BlueSpud 10 years, 8 months ago

And my shader setup

vertexSrc = "attribute vec4 position; attribute vec4 inputTextureCoordinate; varying vec2 textureCoordinate; void main() { gl_Position = position; textureCoordinate = inputTextureCoordinate.xy;}";
fragmentSrc = "varying highp vec2 textureCoordinate; uniform sampler2D videoFrame; precision mediump float; void main() { gl_FragColor = texture2D(videoFrame, textureCoordinate); }";
 
//Position of the triangle (x,y,z) why 4 D:!
//the value is for example, 0.4f is 40% of the glViewPort.
float size = 1.0f;
vertexArray[0]  =  -size; vertexArray[1]  =   size; vertexArray[2]   =  0.0f;
vertexArray[3]  =  -size; vertexArray[4]  =  -size; vertexArray[5]   =  0.0f;
vertexArray[6]  =   size; vertexArray[7]  =  -size; vertexArray[8]   =  0.0f;
vertexArray[9]  =   size; vertexArray[10]  =  size; vertexArray[11]  =  0.0f;
 
// Get dimensions from IwGL
int w = SCREEN_WIDTH;
int h = SCREEN_HEIGHT;
 
//Set the place where we will draw, in this case is a rectangle of wxh with starting position at (0,0).
glViewport(0, 0, w, h) ;
glClearColor(0, 0, 0, 1);

//Create a program to attach vertex and fragments shaders (Source code) to it.
GLuint shaderProgram = glCreateProgram();
//Loading source codes.
GLuint vertexShader = createShader(GL_VERTEX_SHADER, vertexSrc);
GLuint fragmentShader = createShader(GL_FRAGMENT_SHADER, fragmentSrc);
 
//Attach a source code to the whole program (ShaderProgram)
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
 
//Set the location of the "position" variable defined before.
//If I remove this, the code works exactly the same way. I think OpenGL set por default
//to 0 the first variable in the code.
glBindAttribLocation(shaderProgram, 0, "position");
 
//Linking phase, create a whole functionally program with all attached shaders.
glLinkProgram(shaderProgram);
 
//It's like executing a .exe in windows.
glUseProgram(shaderProgram);

Advertisement

Your texture coordinates aren't being passed into the shader. I don't see any texture coordinates.

A quad rendering to the screen could very well be one color if there are no texture coordinates involved. If the coordinates are not given, OpenGl will just take the color from one of the corners (its always the same, I just am not sure which one) and makes the whole polygon that.

This topic is closed to new replies.

Advertisement