Results 1 to 2 of 2

Thread: OpenGL ES 2.0 shaders off-screen blend and color conversion

  1. #1
    Junior Member
    Join Date
    Mar 2011

    OpenGL ES 2.0 shaders off-screen blend and color conversion

    Hi, i am very newbie in OpenGL and Shaders, i would like to use OpenGl to color conversion, and alpha blending (PowerVr SGX 530), could you help me? I have written this so far, but shaders doesnt work, what i am doing wrong?

    Code :
    #include <stdio.h>
    #include <stdlib.h>
    #include <../include/EGL/egl.h>
    #include <../include/EGL/eglext.h>
    #include <../include/GLES2/gl2.h>
    #include <../include/GLES2/gl2ext.h>
    int main() {
    	EGLDisplay eglDisplay = 0;
    	EGLConfig eglConfig = 0;
    	EGLSurface eglSurface = 0;
    	EGLContext eglContext = 0;
    	eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    	EGLint iMajorVersion, iMinorVersion;
    	eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion);
    	EGLint pi32ConfigAttribs[5];
    	pi32ConfigAttribs[0] = EGL_SURFACE_TYPE;
    	pi32ConfigAttribs[1] = EGL_WINDOW_BIT;
    	pi32ConfigAttribs[2] = EGL_RENDERABLE_TYPE;
    	pi32ConfigAttribs[3] = EGL_OPENGL_ES2_BIT;
    	pi32ConfigAttribs[4] = EGL_NONE;
    	EGLint pi32ContextAttribs[3];
    	pi32ContextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION;
    	pi32ContextAttribs[1] = 2;
    	pi32ContextAttribs[2] = EGL_NONE;
    	int iConfigs;
    	eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs);
    	eglSurface = eglCreatePbufferSurface(eglDisplay, eglConfig, NULL);
    	eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, pi32ContextAttribs);
    	eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
    	int renderBufferWidth = 1280;
    	int renderBufferHeight = 720;
    	// now the FBO
    	GLuint fbo = 0;
    	glGenFramebuffers(1, &fbo);
    	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    	GLuint renderBuffer = 0;
    	glGenRenderbuffers(1, &renderBuffer);
    	glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
    	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, renderBufferWidth, renderBufferHeight);
    	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBuffer);
    	GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    	if (status != GL_FRAMEBUFFER_COMPLETE) {
    		printf("Problem with OpenGL framebuffer after specifying color render buffer: %x", status);
    	const char* pszFragShader =
    			"void main (void) { gl_FragColor = vec4(0.0, 0.0, 0.0 , 0.0); }";
    	GLuint uiFragShader, uiVertShader; // Used to hold the fragment and vertex shader handles
    	GLuint uiProgramObject; // Used to hold the program handle (made out of the two previous shaders
    	uiFragShader = glCreateShader(GL_FRAGMENT_SHADER);
    	glShaderSource(uiFragShader, 1, (const char**) &pszFragShader, NULL);
    	GLint bShaderCompiled;
    	glGetShaderiv(uiFragShader, GL_COMPILE_STATUS, &bShaderCompiled);
    	uiProgramObject = glCreateProgram();
    	printf("\n program object =  %d", uiProgramObject);
    	glAttachShader(uiProgramObject, uiFragShader);
    	GLfloat vVertices[] = { -1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f,
    			0.0f };
    	glViewport(0, 0, renderBufferWidth, renderBufferHeight);
    	glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
    	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, vVertices);
    	glDrawArrays(GL_TRIANGLES, 0, 4);
    	eglSwapBuffers(eglDisplay, eglSurface);
    	GLuint * data = (GLuint *) malloc(renderBufferWidth * renderBufferHeight * sizeof(GLuint));
    	glReadPixels(0, 0, renderBufferWidth, renderBufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, data);
    	printf("\npixel = %u", data[2]);
    	return 0;

  2. #2
    Senior Member
    Join Date
    May 2006

    Re: OpenGL ES 2.0 shaders off-screen blend and color convers

    You need a vertex shader.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum |

Similar Threads

  1. Screen Freezes and black screen during game execution on Win
    By Leena in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 07-29-2009, 11:54 AM
  2. Color space conversion
    By Saeed in forum OpenML Coding & Technical Issues
    Replies: 0
    Last Post: 12-12-2004, 05:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts