COCOS2DX problems with off-screen rendering

Source: Internet
Author: User

1. Off-screen rendering process, based on opengles2.0

2.2.6 The simplegame example below, the Nativebegin and Nativeend functions are added to the JNI. Final off-screen drawing process:

Nativebegin (); Nativerender (); Drawing of Cocos2dx ... Nativeend ();
In the Nativebegin function, create a screen-sized FBO, bind a texture and depth, and bind to the currently created FBO. Nativeend the FBO texture to the screen ...

2. cocos2dx-2.2.6 the problem of black screen

But after running the result is brutal black screen ... All right. is also the problem of state disorder, step by step to troubleshoot it:

Between Nativebegin and nativeend if I replace my own render function results OK. It is further proved that the nativebegin and end functions do not coincide with the COCOS2DX render function state. After three days of tracing, the final problem is located in the Nativeend Renderquad code snippet:

 #if 0//this Section would call 0x500 Invalid Enum error.glenable (gl_texture_2d); Checkglerror ("glenable"); #endifglActiveTexture (GL _TEXTURE0); Checkglerror ("glactivetexture");//Glbindtexture (gl_texture_2d, mpostpass.color_id); GlBindTexture (GL_ texture_2d, mpass.color_id), Checkglerror ("glbindtexture"); gluniform1i (Mboard.utexloc, 0); Checkglerror (" Gluniform1i "); float vertices[] = { -1.0,1.0, -1.0,-1.0, 1.0,1.0, 1.0,-1.0};const float texcoords[] = {0,1, 0,0, N, 1,0};g Lvertexattribpointer (Mboard.aposloc, 2, Gl_float, Gl_false, 0, vertices); Glvertexattribpointer (Mboard.auvloc, 2, GL_ FLOAT, Gl_false, 0, texcoords); Glenablevertexattribarray (Mboard.aposloc); Glenablevertexattribarray (MBOARD.AUVLOC) ; Gldrawarrays (Gl_triangle_strip, 0, 4); #if 0glDisableVertexAttribArray (Mboard.auvloc); Gldisablevertexattribarray ( MBOARD.APOSLOC); #endif 
In opengles2.0, you do not need to explicitly call glenable (texture_2d), otherwise 0x500 errors are reported in Logcat. The screen black screen problem is: Close the texture and position properties of the fixed-point array at the end of the drawing ... This causes the next frame to draw when the two properties in the COCOS2DX are not turned on, so that the content drawn to the FBO is black ...

3. cocos2dx-3.2 under the black screen problem 2.2 under the problem, put on 3.2 is still black screen, and there is no warning and error in Logcat. This depressed, it is said that 2.x to 3.x vary greatly. In order to poor this bug, the 3.2 of the rendering code also studied the next ... Introduction of VBO and batch drawing. Back to the black screen problem, can only pass glreadpixels try to read the frame content to write a file to see.

The Nativerender function started for some time, the data is not ready to be black screen normal, until the data is ready to draw content. This is a big distraction for my location problem. Because it is normal to start rendering a black screen, it is only about 100 frames before the content is drawn ...

To construct some specific scenarios for testing:

When content is drawn, the FBO in begin and end only work:

0-100 frames, Nativebegin and nativeend are empty, nativerender directly to the screen. The result is OK.

101 frames, FBO in Nativebegin,1) nativerender is the drawing normal at this time? Then Nativeend,2) Is this screen OK?

102 frames, the nativebegin is still in effect , the previous frame of Nativebegin and nativeend has been in effect, 3) at this time Nativerender no is drawing normal? 4) Nativeend How to finish the screen?

103 frames, repeat 102 mode ...

Question 4 is more obvious, it must be a black screen.

Problem Glreadpixels can only read the currently bound frame buffer by reading the file by writing to see ... The conclusion is 1 normal, 2 draw normal, 3 is already black screen.

Nativeend is the first execution of the subsequent nativerender after the failure of ...

It took the last two or three days to finally locate the problem. The GL drawing state is cached in 3.2, for example Shaderprogram,textureid these things. The cached macro switch is in the ccConfig.h header file:

#ifndef cc_enable_gl_state_cache#define Cc_enable_gl_state_cache 1#endif

Cc_enable_gl_state_cache is defined as 0, and after the GL state cache is turned off, the result is OK.

Or do not call the GL function directly, but instead call the GL instruction through the interface in the Ccglstatecache component, and the result is OK.

4.2.2.6 the next part of the phone left white problem simplegame in the game points in the label text location problem, NEXUS4 phone on the left side of the screen, in the Huawei part of the machine and Xiaomi 3 above, left and the screen is dozens of pixels away. This problem is more Eazy, through Glgetintegerv to get COCOS2DX set viewport actually not 0,0,wid,height,nativebegin in the cocos2d of the set viewport, Use 0,0,wid,height when pasting textures onto the screen in Nativeend. The problem is solved.


COCOS2DX problems with off-screen rendering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.