@Matic
static const char s_v_shader[] =
"attribute vec4 vPosition; \n"
"attribute vec2 my_Texcoor; \n"
"uniform mat4 u_TransMatrix; \n"
"varying vec2 vTexcoor; \n"
"void main() \n"
"{ \n"
" vTexcoor = my_Texcoor; \n"
" gl_Position = u_TransMatrix*vPosition; \n"
"} \n";
static const char s_f_shader[] =
"precision mediump float;\n"
"uniform lowp vec4 Texture; \n "
"uniform sampler2D my_Sampler; \n"
"varying vec2 vTexcoor; \n"
"void main() \n"
"{ \n"
" vec4 tex = texture2D(my_Sampler, vTexcoor); \n"
" gl_FragColor = tex; \n"
"} \n";
#endif
static const char s_v_shader_new[] =
"attribute vec4 vPosition_new; \n"
"attribute vec2 my_Texcoor_new; \n"
"uniform mat4 u_TransMatrix_new; \n"
"varying vec2 vTexcoor_new; \n"
"void main() \n"
"{ \n"
" vTexcoor_new = my_Texcoor_new; \n"
" gl_Position = u_TransMatrix_new*vPosition_new; \n"
"} \n";
static const char s_f_shader_new[] =
"precision mediump float;\n"
//"uniform sampler2D my_Sampler_new; \n"
"uniform lowp vec4 uniformColor;\n"
//"uniform vec4 uniformColor;\n"
"varying vec2 vTexcoor_new; \n"
"void main() \n"
"{ \n"
" gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n"
"} \n";
#endif
const GLfloat vertices[][2] = {
{ -1.0f, -1.0f},
{ 1.0f, -1.0f},
{ -1.0f, 1.0f},
{ 1.0f, 1.0f}
};
const GLfloat texcoords[][2] = {
{ 0.0f, 1.0f},
{ 1.0f, 1.0f},
{ 0.0f, 0.0f},
{ 1.0f, 0.0f}
};
// Triangle Vertex colors.
const GLfloat color[][3] = {
{1.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, 1.0f},
{1.0f, 1.0f, 0.0f}
};
// Start with an identity matrix.
GLfloat transformMatrix[16] =
{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
void LoadShaders_new(const char * vShader, const char * pShader)
{
vertShaderNum_new = glCreateShader(GL_VERTEX_SHADER);
pixelShaderNum_new = glCreateShader(GL_FRAGMENT_SHADER);
#if 1
if (CompileShader(vShader, vertShaderNum_new) == 0)
{
printf("%d: PS compile failed.\n", __LINE__);
return;
}
#endif
if (CompileShader(pShader, pixelShaderNum_new) == 0)
{
printf("%d: VS compile failed.\n", __LINE__);
return;
}
programHandle_new = glCreateProgram();
glAttachShader(programHandle_new, vertShaderNum_new);
glAttachShader(programHandle_new, pixelShaderNum_new);
// Bind vPosition to attribute 0
// glBindAttribLocation ( programHandle_new, 0, "vPosition_new" );
#if 1
glLinkProgram(programHandle_new);
// Check if linking succeeded.
GLint linked = 0;
glGetProgramiv(programHandle_new, GL_LINK_STATUS, &linked);
if (!linked)
{
printf("%d: Link failed.\n", __LINE__);
// Retrieve error buffer size.
GLint errorBufSize, errorLength;
glGetShaderiv(programHandle_new, GL_INFO_LOG_LENGTH, &errorBufSize);
char * infoLog = (char*)malloc(errorBufSize * sizeof (char) + 1);
if (infoLog)
{
// Retrieve error.
glGetProgramInfoLog(programHandle_new, errorBufSize, &errorLength, infoLog);
infoLog[errorBufSize + 1] = '\0';
fprintf(stderr, "%s", infoLog);
free(infoLog);
}
return;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// glUseProgram(programHandle_new);
#endif
}
// Wrapper to load vetex and pixel shader.
void LoadShaders(const char * vShader, const char * pShader)
{
vertShaderNum = glCreateShader(GL_VERTEX_SHADER);
pixelShaderNum = glCreateShader(GL_FRAGMENT_SHADER);
if (CompileShader(vShader, vertShaderNum) == 0)
{
printf("%d: PS compile failed.\n", __LINE__);
return;
}
if (CompileShader(pShader, pixelShaderNum) == 0)
{
printf("%d: VS compile failed.\n", __LINE__);
return;
}
programHandle = glCreateProgram();
glAttachShader(programHandle, vertShaderNum);
glAttachShader(programHandle, pixelShaderNum);
// Bind vPosition to attribute 0
glBindAttribLocation ( programHandle, 0, "vPosition" );
glLinkProgram(programHandle);
// Check if linking succeeded.
GLint linked = 0;
glGetProgramiv(programHandle, GL_LINK_STATUS, &linked);
if (!linked)
{
printf("%d: Link failed.\n", __LINE__);
// Retrieve error buffer size.
GLint errorBufSize, errorLength;
glGetShaderiv(programHandle, GL_INFO_LOG_LENGTH, &errorBufSize);
char * infoLog = (char*)malloc(errorBufSize * sizeof (char) + 1);
if (infoLog)
{
// Retrieve error.
glGetProgramInfoLog(programHandle, errorBufSize, &errorLength, infoLog);
infoLog[errorBufSize + 1] = '\0';
fprintf(stderr, "%s", infoLog);
free(infoLog);
}
return;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glUseProgram(programHandle);
}
main()
{
LoadShaders(s_v_shader, s_f_shader);
LoadShaders_new(s_v_shader_new, s_f_shader_new);
// Grab location of shader attributes.
locVertices = glGetAttribLocation(programHandle, "vPosition");
//locColors = glGetAttribLocation(programHandle, "my_Color");
locTexcoord = glGetAttribLocation(programHandle, "my_Texcoor");
// Transform Matrix is uniform for all vertices here.
locTransformMat = glGetUniformLocation(programHandle, "u_TransMatrix");
locSampler = glGetUniformLocation(programHandle, "my_Sampler");
/* Create the texture. */
glGenTextures(1, &gTexObj);
glBindTexture(GL_TEXTURE_2D, gTexObj);
if (gTexObj == 0)
{
printf("Could not load the texture \n");
return -1;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);
glUniformMatrix4fv(locTransformMat, 1, GL_FALSE, transformMatrix);
glUniform1i(locSampler, 0);
glClearColor(0.0f, 0.5f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
while(1)
{
glEnableVertexAttribArray(locVertices);
glEnableVertexAttribArray(locTexcoord);
// set data in the arrays.
glVertexAttribPointer(locVertices, 2, GL_FLOAT, GL_FALSE, 0, &vertices[0][0]);
glVertexAttribPointer(locTexcoord, 2, GL_FLOAT, GL_FALSE, 0, &texcoords[0][0]);
>>>>>>>>>>>>>>>>>>>>>> Render Video logic on Texture <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
float vVertices[] =
{
-0.85f, -0.9f, -0.6f, -0.5f,
};
glUseProgram(programHandle_new); >>>>>>>>>>>>>>>>>>>>>>> Video render stops display is not streaming
glVertexAttribPointer ( 0, 2, GL_FLOAT, GL_FALSE, 0, vVertices );
glEnableVertexAttribArray (0 );
glDrawArrays ( GL_LINES , 0, 2 );
glLineWidth( width_test );
}
}
}