Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
bobbyblues
Posts: 3
Registered: ‎01-20-2012
My Carrier: None

OpenGL ES how to change resolution?

Hello,

 

I am new to mobile device development, and was trying a little bit of OpenGL ES on my blackberry playbook.

 

I am running the native SDK 1, and started my project from the OpenGL ES 1.1 template.

I modified it so it would use OpenGL ES 2. What my program does basically is sending two triangles in order to cover all the screen, and then using the fragment shader to do some raymarching.

 

However the result is very slow, so I wanted to decrease the resolution, this way my fragment shader is not called as often as before. To do that, I divided by two the resolution in the main.c file.

 

GLint surface_width, surface_height;

eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);


// My modifications
surface_width /= 2.f; surface_height /= 2.f; ... glViewport(0, 0, surface_width, surface_height);

 

 

 

So now my program is fast, but is displayed on a fourth of the screen. I guess I missed a step here, but can't find where. I tried dividing some resolution values in the bbutil.c with no results.

 

Would someone know how to solve this? 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Carrier: Verizon

Re: OpenGL ES how to change resolution?

I kept trying to think this over but all my ideas wouldn't work with making a "low resolution" game. I did a quick search and found this: http://gamedev.stackexchange.com/questions/7449/is-there-a-global-low-resolution-filter-for-opengl which brought up a good point. Use a framebuffer.

 

This way you can render to whatever resolution you want, then simply draw the framebuffer to the screen (there is a bit of extra work there if you treat the FBO as a texture).

 

It is a little extra work but it still works quite well and fast.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Contributor
bobbyblues
Posts: 3
Registered: ‎01-20-2012
My Carrier: None

Re: OpenGL ES how to change resolution?

Oh yes, I did not think of using a FBO. That will work if I don't find any native way. It's weird though as when you use OpenGL on a computer the resolution of OpenGL is not related to the resolution of your window.

 

Thank you anyway, I will try that :smileyhappy: 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Carrier: Verizon

Re: OpenGL ES how to change resolution?

I know what you mean, but that's the nature of working on a mobile device. Come back if you have any issues.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
BlackBerry Development Advisor (Retired)
dtomilovskiy
Posts: 36
Registered: ‎10-26-2011
My Carrier: Rogers

Re: OpenGL ES how to change resolution?

Hey bobbyblues.

 

The result that you see is a correct behavior. Under the covers bbutil sets up a native window surface, calling  

 

glViewport(0, 0, surface_width / 2, surface_height / 2);

 

Tells GL driver to render to only a quarter of your screen.

 

Instead, you need 2 separate steps

 

1. Render at desired (lower) resolution.

2. Resize results from step1 to PlayBook's 1024x600.

 

There are several ways to do something like this. Probably the easiest is to render to a gl texture in step 1 and later on apply this texture to a full-screen quad to get it "resized".

 

These should be a good starting point on this technique:

 

http://www.opengl.org/wiki/Framebuffer_Object

http://nehe.gamedev.net/tutorial/radial_blur__rendering_to_a_texture/18004/

 

 

Please use plain text.
New Contributor
bobbyblues
Posts: 3
Registered: ‎01-20-2012
My Carrier: None

Re: OpenGL ES how to change resolution?

Hello,

 

thank you for your links. This weekend I implemented a FBO to render in a texture and then put the texture on a quad.

 

However, it still needs some debuging, as my texture is all black. I will keep investigating that, and let you know when it works :smileyhappy:

 

Hopefully I will find in your links where my mistake lies.

 

Thanks again! 

Please use plain text.