Game thread AND render thread [OpenGL]?

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Re: Game thread AND render thread [OpenGL]?

Postby yaolin170 » Fri Jul 16, 2010 10:46 am

Hi Skywhy,
Thanks very much for your reply!

for your solution about using OpenGL ES to draw everything ,i still have something confused.

for example ,in the splash screen of the game ,I want to draw the splash .what function should i call according to the OpenGL ES API ? call "glDrawTexiOES" function to draw a texture ,right ? but is that really a good idea ? i think that's a little bit complicated ,and maybe not faster than Canvas !

I have read the Graphics System about Android .All the elements are rendered onto the Surface ,then the Surface will be drew onto the buffer .Each Surface will create a object for Canvas .
Canvas is used to develop 2D elements . 2D and 3D elments are drew onto the Surface .
as I said in the previous post ,I draw all the 2D things onto the Canvas, and draw all 3D things onto the GLSurface.
then the most important thing for me is that :
if I can find a link between the Canvas and GLSurfaceView .or if there are some special API function that can bind them ,then everything will gonna be ok ,do you think so ?

Just like J2ME 3D .in j2me ,all the 2d things are drew onto the Graphics ,and all the 3D things are drew onto Graphics3D.then J2ME links them by calling funcion "Graphics3D.bindTarget(Graphics)" ,so that at last ,all the 3D things can be drew onto the screen ... I just don't know whether there are some functions like "bindTarget" in j2me ,I think there must have some API functions .but i can't find them .

do you or anybody here know that ? if you have any idea about this ,please let me know ,thank you in advance !

Skywhy ,Thank you again !

Allen
No Gods ,No Kings,Only Man!
yaolin170
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Oct 23, 2009 7:21 am

Top

Re: Game thread AND render thread [OpenGL]?

Postby Skywhy » Fri Jul 16, 2010 10:54 am

2D stuff in opengl:
- set 2d projection
- draw quad with texture on it (this is now your sprite, splash, what ever you want it to be) using glDrawElements for example.

done.

You just need to render a quad or two triangles with the texture on it, and that's how you do it. voila hardware accelerated fast 2D graphics with opengl es. If you still don't understand, make a thread for it and don't revive old threads just to hijack them.

Again, there are thousands and thousands tutorials on how to use opengl for 2D graphics. You just render quads or triangles with textures on them and the texture can be what ever; sprite, splash screen, score, text etc.
Skywhy
Developer
Developer
 
Posts: 35
Joined: Tue Oct 20, 2009 7:55 pm

Re: Game thread AND render thread [OpenGL]?

Postby yaolin170 » Mon Jul 19, 2010 2:58 am

Hi,SkyWhy,
Thank you for your replying again !

I know what you said ,but I just think for example ,in the main menu state of the game .there are many options :new game , score ,continue game and so on ,every word are drew by using images not just fonts .so to draw a 2D image ,everytime ,i have to draw a quad first ,then render a texture on it ? i think that's apparently complicated than just use Canvas ? do you think so ?
No Gods ,No Kings,Only Man!
yaolin170
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Oct 23, 2009 7:21 am

Re: Game thread AND render thread [OpenGL]?

Postby yaolin170 » Mon Jul 19, 2010 4:05 am

in a word ,I just want to draw all images to screen directly for all 2D parts ,not by drawing a quad first .. do you know there are any API functions that can do that ? That's why I select "glDrawTexiOES" to draw a texture..but I still think all these opengl drawing are not faster than draw Images by using Canvas and less convenient than Canvas.
No Gods ,No Kings,Only Man!
yaolin170
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Oct 23, 2009 7:21 am

Re:

Postby seed » Mon Jul 19, 2010 4:08 pm

zorro wrote:I was saying that by running the rendering and game update threads in parallel, if the game update thead is doing some heavy math tasks (for ex. physics) the rendering thead will loop faster and in the end for every game update 'frame' completed the rendering thread would render two 'frames'. But these 2 frames will be identical because they were computed using data from the previous game thread update loop. So the extra frames are no usefull at all, that's what I think..


I agree with this. My first game has all the game logic and rendering in the OpenGL thread. Works great. 40-50 FPS with a lot of graphics and tons of collision detection. Rendering extra frames in the "render loop" takes away from CPU in the "game loop" IMHO. Two threads will definitely get you extra FPS, but if they are not unique frames, then so what.

regards
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: Game thread AND render thread [OpenGL]?

Postby mark@project8games.com » Mon Jul 19, 2010 10:57 pm

yaolin170 wrote:in a word ,I just want to draw all images to screen directly for all 2D parts ,not by drawing a quad first .. do you know there are any API functions that can do that ? That's why I select "glDrawTexiOES" to draw a texture..but I still think all these opengl drawing are not faster than draw Images by using Canvas and less convenient than Canvas.


Depending on the complexity of the game, desired framerate and actual # of images to draw, it may be possibly to get away with writing a real-time game using only canvas.

However, and this is coming from personal experience, don't start down that route. You will eventually add complexity to the point where you cannot tune out the overhead that canvas introduces, and nothing is worse than a game with crappy FPS.

Unfortunately, there is a bit of learning/setup you will need to do to implement OpenGL, but luckily, you do it once and repeat. There's tons of tutorials out there, just start googling.

In short, sorry, there is no silver bullet. You have to go down the full opengl route.
User avatar
mark@project8games.com
Developer
Developer
 
Posts: 41
Joined: Tue Mar 02, 2010 8:33 pm

Top

Re: Game thread AND render thread [OpenGL]?

Postby Skywhy » Tue Jul 20, 2010 2:20 pm

The reason I told you to use textured triangles is because it's fast. Batch max amount of triangles together and render them with one or as minimal amount of glDraw* calls as possible. Obviously it's more complex but that's life.

In simple menu's you can easily get away by just creating an abstract interface to OpenGL that you just pass a image (texture, sprite, call it what you want) to render and x,y coordinates. But if you really need it to be cutting edge efficient you need to start batching as many triangles together as possible. And if you think that OpenGL ES is not as fast or faster as Java Canvas :shock: ... There is a reason why OpenGL ES is on Android and why it's pretty much the industry standard cross-platform API for 2D and 3D graphics on embedded systems.

Just sit down and start learning OpenGL ES. Not much more to it really. Just like the above poster said. Obviously you can do it with the Canvases but then you are in a wrong thread asking for help. This thread WAS specifically for rendering in OpenGL ES and multithreading.
Skywhy
Developer
Developer
 
Posts: 35
Joined: Tue Oct 20, 2009 7:55 pm

Re: Game thread AND render thread [OpenGL]?

Postby seed » Tue Jul 20, 2010 4:54 pm

yaolin170 wrote:in a word ,I just want to draw all images to screen directly for all 2D parts ,not by drawing a quad first .. do you know there are any API functions that can do that ? That's why I select "glDrawTexiOES" to draw a texture..but I still think all these opengl drawing are not faster than draw Images by using Canvas and less convenient than Canvas.


You are drawing a textured quad, not "drawing a quad first". Write a quad class with a draw method and then you have your own API function. Should take a 10 minute search of the web and 20 minutes to test the code. Your being needlessly intimidated which is a bad way to get started - IMHO. Good luck.

Regards
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: Game thread AND render thread [OpenGL]?

Postby yaolin170 » Wed Jul 21, 2010 9:07 am

Hi guys,
thank you for your suggestions !
in fact ,I am using opengl es to draw the 2d images by accepting your opnions now .

and by the way ,the reason why i don't want to draw the 2d images by the opengl es are these:
1) for most menus ,there are many 2d animations .I have implemented the play of the animations by java on android platform ..
2) apparently ,the size of texture is limited .right ? the size must be 2,4,8,16,32,64,128..and so on .for example ,if i need an image ,the size is : 30X18 , maybe i have to resize its size to 32X 16 to let the image be used in the opengl es .apparently ,it will enlarge the size of the game package ,and also have influence on the memory used in the game ,right ?
as we know .the android platform not only support jave ,but also support C++/c ,and etc. i think it is very convience for us to develop software by using java or c++/c as we like to use . so i decide to draw the 2d parts in the game by using java ,draw 3d parts by using NDK ...
I still think there must have some API functions that can link "Canvas" and "GlSurface" just like in j2me .Graphics can bind with Graphics3D .. but just i don't know them now !
anyway ,thank you guys opnion again ! i learn much from you !

Allen
No Gods ,No Kings,Only Man!
yaolin170
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Oct 23, 2009 7:21 am

Re: Game thread AND render thread [OpenGL]?

Postby seed » Wed Jul 21, 2010 4:23 pm

yaolin170 wrote:2) apparently ,the size of texture is limited .right ? the size must be 2,4,8,16,32,64,128..and so on .for example ,if i need an image ,the size is : 30X18 , maybe i have to resize its size to 32X 16 to let the image be used in the opengl es


The best way to handle this in ES is to use one composite texture, which has all of your little textures on it. Then you can change the texture coordinates you give to ES to only display the bit of the texture you want.

For example, you can put your little 30x18 texture in the upper left corner of a 512x512 texture and use the following as your quad's texture coordinates.

{ 0, 0,
0, 18f/512f,
32f/512f, 18f/512f,
32f/512f, 0 }

stick a bunch of other little textures all over the single large 512x512 texture and you are good to go. This has the additional advantage that you can skip a texture bind between the rendering of each quad making it a little faster. Heck, you can probably do a whole game with only a single texture and doing the texture bind in the GL initialization rather than in each draw frame.

Hope this is useful.

regards
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: Game thread AND render thread [OpenGL]?

Postby yaolin170 » Fri Jul 23, 2010 8:36 am

Hi seed,

thank you for your reply !
that's a good idea ,that's helpful for me !
I am a novice in opengl , if i am mistaken ,please correct me !
No Gods ,No Kings,Only Man!
yaolin170
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Oct 23, 2009 7:21 am

Re: Game thread AND render thread [OpenGL]?

Postby multiplydivide » Thu Jun 23, 2011 5:46 pm

Hi nstegg,
I was wonder what a couple lines of your code are doing... specifically

renderer.addListener(new GameListener());
what is the function of this GameListener?

updater = new GameUpdater(inputHandler);
and the function of this input handler? I assume the input handler handles the capture of UI?

Thanks,
~Spaceaholic
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Top
Previous

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests