How To Draw 3D Graphics?

This is a sample application which shows how to create 3D graphics using OpenGL in android.

Underlying Algorithm:

Basic description of algorithm in step by step form:
1.) Create a Project Graphics3d.
2.) Put an image in res/drawable.
3.) Create a custom view MyGLView.java ,which will look like this:

 

 

 

4.) In OpenGL ES on Android, drawing is separated out into a rendering class which is responsible for initializing and drawing the entire screen.
5.) Create MyGLRenderer.java ,which will look like this:

 

 

 

6.) Create MyCube.java, which will look like this:

 

 

 

7.) Run the Application.

Steps to Create:

1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. Graphics3d. Enter following information:
Project name: Graphics3d
Build Target: Google APIs
Application name: Graphics3d
Package name: app. Com.app.Graphics3d
Create Activity: Graphics3d

On Clicking Finish Graphics3d code structure is generated with the necessary Android Packages being imported along with Graphics3d.java. Graphics3d class will look like following:

 

 

 

Output โ€“The final output:

Leave a Comment:

30 comments
Joshua Maerten says June 20, 2011

How does it come that your image got a transperancy,
is it possible to have no transparancy ?
joshua

Reply
Sushant says June 21, 2011

The image I used is transparent image only. If you don’t want any transparency you can use a image with some background.

Thanks..

Reply
sandesh says July 5, 2011

Hello sir,

Please tell me, can we use this code for android 2.3.3? when i try this on 2.3.3 its saying application stopped unexpectedly . Please help me

Regards,
Sandesh

Reply
sandesh G C says July 5, 2011

Hello sir,

Please tell me, can we use this code for android 2.3.3? when i try this on 2.3.3 its saying application stopped unexpectedly . Please help me

Regards,
Sandesh

Reply
    Sushant says July 6, 2011

    Hello Sandesh,

    There will be no issues if you run it on android 2.3.3. You might didn’t have any graphics image to be drawn in your drawable folder which causes a force close. If you need more help please share your logcat results while running this app.

    Reply
sandesh G C says July 6, 2011

Thank you very much sir, its working fine now . Can you please help me how can i change the texture dynamically? I mean I want to change the texture when the cube is rotating.

Reply
sandesh G C says July 7, 2011

Hello sir,

Thanks for the help, i am able to change the texture dynamically now . Please tell me how to remove the transparency of the texture. It will be very helpful if you help me in this .

Thanks in advance,
Sandesh.

Reply
Sushant says July 7, 2011

what images your are using.. png or jepg?

Can you share your code here so that I can check..

Thanks.

Reply
Anish says July 14, 2011

how to load .3ds file . which class to use for laoding .3ds file .

Reply
anish says July 14, 2011

how to load .3ds file , the way you loaded the bitmap file how to load .3ds file

Reply
El pollo diablo says August 9, 2011

Amazing tutorial!

I was wondering why are you using an intBuffer instead of a floatBuffer in myCube.java? Very new to OpenGLES for android so that might be a rather elementary question…

Reply
KIRABO says September 26, 2011

hi when i run the application onto a device only a cube is visible without the image any ideas on how to solve this?

Reply
Akhil says October 3, 2011

Hello

Hey can you please tell me how to dynamically load the images to those textures??? What I want is whenever I click a button the texture needs to be changed to other image…

Thanks
Akhil

Reply
Rishabh says October 26, 2011

Hi Guys

Can any buddy send me a link for ebook where canvas is explaine with starting actully i am beginner in this field & no knowladge about how i can develope appliaction.

Reply
Sebastian Cheung says November 29, 2011

I added an image and named it as one.png. How come I still get error message even after doing a clean?

MyCube.loadTexture(gl, context, R.drawable.one);

Seb

Reply
Sebastian Cheung says November 29, 2011

I added an image and named it as one.png. How come I still get error message even after doing a clean? Please help

MyCube.loadTexture(gl, context, R.drawable.one);

Seb

Reply
ravi says January 13, 2012

hello
upload that image also with this code .

Reply
John says February 8, 2012

Thank you so much for this excellent example!!

Reply
Oloan says July 12, 2012

Hi, Why I always get white box w/o any picture attached there?
Thanks

Reply
Anne says July 16, 2012

How to add two images to the above cube?

Reply
Anne says July 16, 2012

Hello, Can you please tell how to add two images to the above cube?

Reply
Anne says July 16, 2012

Hello, can you please tell me how to two images for the above cube?

Reply
Anne says July 16, 2012

I’m having trouble with adding two images for the above cube. Can you please let me know how to add two images?

Reply
Raj1_24apr says August 8, 2012

getting some run time error do i need to add something in the manifest file

Reply
Rishabh says January 5, 2013

sir i want to make gaming application but my package not supported instead it support on book

Reply
ss moon says May 29, 2013

Not transparent PNG files.
Here’s a sample image you upload them proud.
Only the white cube watering.
bmp, jpg, png Not all mind if l test.

Reply
Avinesh says June 5, 2013

I don get the output Sir … Pls Help me

Reply
Avinesh Ram says June 5, 2013

I don get your 2nd point in the above algo.. u ve stated (i.e.,) Put an image in res/drawable folder …

Reply
Sebi says December 22, 2014

Nice tutorial ๐Ÿ™‚

Im just trying to place 2 objects at the screen…

Reply
Add Your Reply