void RenderTarget::onEndFrame(int layer) { #if (TARGET_PLATFORM == PLATFORM_WIN32) eglSwapBuffers(m_eglDisplay, m_eglSurface); TestGLError("RenderTarget::onEndFrame | eglSwapBuffers"); #else Present(); #endif }
void RenderTarget::onAttach() { #if (TARGET_PLATFORM == PLATFORM_WIN32) eglMakeCurrent(m_eglDisplay,m_eglSurface,m_eglSurface,rc); glBindFramebuffer(GL_FRAMEBUFFER,m_FrameBufferObj); TestGLError("RenderTarget::onAttach | glBindFramebuffer"); #else #endif }
/*!***************************************************************************************************************************************** @Function InitialiseBuffer @Output vertexBuffer Handle to a vertex buffer object @Return Whether the function succeeds or not. @Description Initialises shaders, buffers and other state required to begin rendering with OpenGL ES *******************************************************************************************************************************************/ bool InitialiseBuffer(GLuint &vertexBuffer) { /* Concept: Vertices When rendering a polygon or model to screen, OpenGL ES has to be told where to draw the object, and more fundamentally what shape it is. The data used to do this is referred to as vertices, points in 3D space which are usually collected into groups of three to render as triangles. Fundamentally, any advanced 3D shape in OpenGL ES is constructed from a series of these vertices - each vertex representing one corner of a polygon. */ /* Concept: Buffer Objects To operate on any data, OpenGL first needs to be able to access it. The GPU maintains a separate pool of memory it uses independent of the CPU. Whilst on many embedded systems these are in the same physical memory, the distinction exists so that they can use and allocate memory without having to worry about synchronising with any other processors in the device. To this end, data needs to be uploaded into buffers, which are essentially a reserved bit of memory for the GPU to use. By creating a buffer and giving it some data we can tell the GPU how to render a triangle. */ // Vertex data containing the positions of each point of the triangle GLfloat vertexData[] = {-0.4f,-0.4f, 0.0f, // Bottom Left 0.4f,-0.4f, 0.0f, // Bottom Right 0.0f, 0.4f, 0.0f}; // Top Middle // Generate a buffer object glGenBuffers(1, &vertexBuffer); // Bind buffer as an vertex buffer so we can fill it with data glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); /* Set the buffer's size, data and usage Note the last argument - GL_STATIC_DRAW. This tells the driver that we intend to read from the buffer on the GPU, and don't intend to modify the data until we're done with it. */ glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW); if (!TestGLError("glBufferData")) { return false; } return true; }
void ModelDrawer::SetupS3OBasicDrawing (const Vector3& teamcol) { glColor3f(1,1,1); // RGB = Texture * Alpha + Teamcolor * (1-Alpha) glActiveTextureARB(GL_TEXTURE0_ARB); glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB); glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB, GL_CONSTANT_ARB); glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB, GL_ONE_MINUS_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB); glEnable(GL_TEXTURE_2D); // set team color float tc[4]={teamcol.x,teamcol.y,teamcol.z,1.0f}; glTexEnvfv(GL_TEXTURE_ENV,GL_TEXTURE_ENV_COLOR, tc); // bind texture 0 glBindTexture (GL_TEXTURE_2D, model->textures[0]->glIdent); // RGB = Primary Color * Previous glActiveTextureARB(GL_TEXTURE1_ARB); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB); glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, whiteTexture); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); TestGLError (); }
/*!***************************************************************************************************************************************** @Function RenderScene @Input eglDisplay The EGLDisplay used by the application @Input eglSurface The EGLSurface created from the native window. @Input nativeDisplay The native display used by the application @Return Whether the function succeeds or not. @Description Renders the scene to the framebuffer. Usually called within a loop. *******************************************************************************************************************************************/ bool RenderScene( EGLDisplay eglDisplay, EGLSurface eglSurface, Display* nativeDisplay ) { /* Set the clear color At the start of a frame, generally you clear the image to tell OpenGL ES that you're done with whatever was there before and want to draw a new frame. In order to do that however, OpenGL ES needs to know what colour to set in the image's place. glClearColor sets this value as 4 floating point values between 0.0 and 1.x, as the Red, Green, Blue and Alpha channels. Each value represents the intensity of the particular channel, with all 0.0 being transparent black, and all 1.x being opaque white. Subsequent calls to glClear with the colour bit will clear the frame buffer to this value. The functions glClearDepth and glClearStencil allow an application to do the same with depth and stencil values respectively. */ glClearColor(0.6f, 0.8f, 1.0f, 1.0f); /* Clears the color buffer. glClear is used here with the Colour Buffer to clear the colour. It can also be used to clear the depth or stencil buffer using GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT, respectively. */ glClear(GL_COLOR_BUFFER_BIT); // Enable the vertex array glEnableClientState(GL_VERTEX_ARRAY); // Sets the vertex data to this attribute index, with the number of floats in each position glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), (GLvoid*)0); if (!TestGLError("glVertexAttribPointer")) { return false; } // Set a color to render glColor4f(1.0f, 1.0f, 0.66f, 1.0f); /* Draw the triangle glDrawArrays is a draw call, and executes the shader program using the vertices and other state set by the user. Draw calls are the functions which tell OpenGL ES when to actually draw something to the framebuffer given the current state. glDrawArrays causes the vertices to be submitted sequentially from the position given by the "first" argument until it has processed "count" vertices. Other draw calls exist, notably glDrawElements which also accepts index data to allow the user to specify that some vertices are accessed multiple times, without copying the vertex multiple times. Others include versions of the above that allow the user to draw the same object multiple times with slightly different data, and a version of glDrawElements which allows a user to restrict the actual indices accessed. */ glDrawArrays(GL_TRIANGLES, 0, 3); if (!TestGLError("glDrawArrays")) { return false; } /* Present the display data to the screen. When rendering to a Window surface, OpenGL ES is double buffered. This means that OpenGL ES renders directly to one frame buffer, known as the back buffer, whilst the display reads from another - the front buffer. eglSwapBuffers signals to the windowing system that OpenGL ES 1.x has finished rendering a scene, and that the display should now draw to the screen from the new data. At the same time, the front buffer is made available for OpenGL ES 1.x to start rendering to. In effect, this call swaps the front and back buffers. */ if (!eglSwapBuffers(eglDisplay, eglSurface) ) { TestEGLError("eglSwapBuffers"); return false; } // Check for messages from the windowing system. int numberOfMessages = XPending(nativeDisplay); for( int i = 0; i < numberOfMessages; i++ ) { XEvent event; XNextEvent(nativeDisplay, &event); switch( event.type ) { // Exit on window close case ClientMessage: // Exit on mouse click case ButtonPress: case DestroyNotify: return false; default: break; } } return true; }