zezba9000
Posts: 35
Joined: Wed Jan 16, 2013 2:59 am

Cannot get eglSwapBuffers to work!

Sat Jan 19, 2013 4:27 am

I for the life of me can not get GLES to present any data to my Pi's screen.
Im setting eglMakeCurrent, glBindFramebuffer, glViewPort, glClearColor, glClear and then eglSwapBuffer... Its getting over 60fps but nothing shows on the screen.

I'm using "Soft-float Debian “wheezy”" with Mono C#.

Here is how I create egl:

Code: Select all

//Get DC
					RaspberryPi.bcm_host_init();
					handle = window.Handle;
					dc = EGL.GetDisplay(IntPtr.Zero);
					
					int major, minor;
					if (!EGL.Initialize(dc, out major, out minor))
					{
						Debug.ThrowError("Video", string.Format("Failed to initialize display connection, Error {0}", EGL.GetError()));
					}
					if (minor != EGL.OPENGL_ES2_BIT) Debug.ThrowError("Video", "GLES2 is not supported");
					
					int[] pixelFormat = new int[] 
					{ 
						//EGL.RENDERABLE_TYPE, EGL.OPENGL_ES2_BIT,
						
						//EGL.SURFACE_TYPE, EGL.WINDOW_BIT,
						EGL.RED_SIZE, 5,
						EGL.GREEN_SIZE, 6,
						EGL.BLUE_SIZE, 5,
						EGL.ALPHA_SIZE, EGL.DONT_CARE,
						
						EGL.DEPTH_SIZE, EGL.DONT_CARE,
						EGL.STENCIL_SIZE, EGL.DONT_CARE,
						
						EGL.SAMPLE_BUFFERS, 0,
						//EGL.SAMPLES, 0,
						
						//EGL.MIN_SWAP_INTERVAL, 0,
						//EGL.MAX_SWAP_INTERVAL, 1,
						
						EGL.NONE,
					};
					
					int num_configs;
					var configs = new IntPtr();
					if (EGL.ChooseConfig(dc, pixelFormat, &configs, 1, &num_configs) == 0 || num_configs == 0)
					{
						Debug.ThrowError("Video", string.Format("Failed to retrieve GraphicsMode, error {0}", EGL.GetError()));
					}
					
					if (EGL.BindAPI(EGL.OPENGL_ES_API) == 0) Debug.ThrowError("Video", "Failed to bind GLES API");;
					
					int[] attrib_list = new int[]
					{
						EGL.CONTEXT_CLIENT_VERSION, 2,
						EGL.NONE
					};
					
					ctx = EGL.CreateContext(dc, configs, IntPtr.Zero, attrib_list);
					if (ctx == IntPtr.Zero) Debug.ThrowError("Video", "Failed to create context");
					
					const int piDisplay = 0;
					uint piWidth = 0, piHeight = 0;
					if (RaspberryPi.graphics_get_display_size(piDisplay, &piWidth, &piHeight) < 0) Debug.ThrowError("Video", "Failed to get display size");
					piWidth = 640;
					piHeight = 480;
					Console.WriteLine("piWidth - " + piWidth);
					Console.WriteLine("piHeight - " + piHeight);
					
					IntPtr dispman_display = RaspberryPi.vc_dispmanx_display_open(piDisplay);
					if (dispman_display == IntPtr.Zero) Debug.ThrowError("Video", "Failed: vc_dispmanx_display_open");
					
					IntPtr dispman_update = RaspberryPi.vc_dispmanx_update_start(0);
					if (dispman_update == IntPtr.Zero) Debug.ThrowError("Video", "Failed: vc_dispmanx_update_start");
					
					VC_RECT_T dstRect = new VC_RECT_T()
					{
						x = 0,
						y = 0,
						width = (int)piWidth,
						height = (int)piHeight
					};
					VC_RECT_T srcRect = new VC_RECT_T()
					{
						x = 0,
						y = 0,
						width = (int)(piWidth << 16),
						height = (int)(piHeight << 16)
					};
					IntPtr dispman_element = RaspberryPi.vc_dispmanx_element_add(dispman_update, dispman_display, 0, &dstRect, IntPtr.Zero, &srcRect, RaspberryPi.DISPMANX_PROTECTION_NONE, IntPtr.Zero, IntPtr.Zero, 0);
					if (dispman_element == IntPtr.Zero) Debug.ThrowError("Video", "Failed: vc_dispmanx_element_add");
					
					RaspberryPi.vc_dispmanx_update_submit_sync(dispman_update);
					
					DISPMANX_WINDOW_T nativeWindow = new DISPMANX_WINDOW_T()
					{
						element = dispman_element,
						width = (int)piWidth,
						height = (int)piHeight
					};
					surface = EGL.CreateWindowSurface(dc, configs, new IntPtr(&nativeWindow), null);
					//surface = EGL.CreateWindowSurface(dc, configs[0], handle, null);// <<<<<<<<<<<<<<<<<<<<<<<<<<<< used in x11
					if (surface == IntPtr.Zero) Debug.ThrowError("Video", "Failed to create window surface");
					
					if (EGL.MakeCurrent(dc, surface, surface, ctx) == 0) Debug.ThrowError("Video", "Failed to make EGL context current");
					//if (!EGL.SwapInterval(dc, vSync ? 1 : 0)) Debug.ThrowError("Video", "Failed to set vSync");

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: eglSwapBuffers does not work!

Sat Jan 19, 2013 10:57 am

I can't see any code there that look like it should draw anything so maybe that is the problem ! ;)

Have you compared your setup code to the known working examples in /opt/vc/src/hello_pi ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26442
Joined: Sat Jul 30, 2011 7:41 pm

Re: Cannot get eglSwapBuffers to work!

Sat Jan 19, 2013 11:00 am

Mod; Changed thread title - eglSwapBuffer does work, the problem is that the OP cannot get it to work.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

zezba9000
Posts: 35
Joined: Wed Jan 16, 2013 2:59 am

Re: Cannot get eglSwapBuffers to work!

Sat Jan 19, 2013 7:04 pm

@PeterO

For rendering I just do:

Code: Select all

EGL.MakeCurrent(dc, surface, surface, ctx);
GL.BindFramebuffer(GL.FRAMEBUFFER, 0);
GL.ClearColor(r, g, b, a);
GL.Clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
EGL.SwapBuffers(dc, surface);

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: Cannot get eglSwapBuffers to work!

Sat Jan 19, 2013 7:21 pm

zezba9000 wrote:@PeterO

For rendering I just do:

Code: Select all

EGL.MakeCurrent(dc, surface, surface, ctx);
GL.BindFramebuffer(GL.FRAMEBUFFER, 0);
GL.ClearColor(r, g, b, a);
GL.Clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
EGL.SwapBuffers(dc, surface);
What values for rgba ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

zezba9000
Posts: 35
Joined: Wed Jan 16, 2013 2:59 am

Re: Cannot get eglSwapBuffers to work!

Sat Jan 19, 2013 9:50 pm

Sry all got it working.

Turns out "DISPMANX_WINDOW_T" had to have its memory pinned in .NET
otherwise it gets garbage collected and screws the program up.

Heres my working init code: https://github.com/reignstudios/ReignSD ... eo.cs#L141

Return to “OpenGLES”