Posts

Showing posts with the label OpenGL

3d Tunnel OpenGL Source code - iPhone OpenGL ES compatible !

Image
I am releasing source code of the iPhone OpenGL ES compatible Never-Ending Tunnel Source Code. The code is done using SDL on Windows only. But the OpenGL elements use only Triangle strips and all OpenGL ES compatible functions and porting to iPhone is a cakewalk. I have searched on the web and never found a ES compatible version which is easily portable, so here we go enjoy. I have intentionally left a small glitch in Texture Coordinate generation, which actually looks pretty according to me. If you need I can help you to fix is easily. Some important notes :- No Models present - The Tunnel is a torus which is completely procedurally generated.. so the torus properties can be changed easily. The Texture generation part is platform dependent. The files RTexture.h and RTexture.cpp is almost completely copy-paste reusable :D DO NOT REMOVE - #define QUAKEBOY_IS_AWESOME (!) Download Source code (along with SDL Library and Binaries included - 1.36 MB)

How to load a texture in Android OpenGL ES

Here is how you can easily load a texture from any image format - PNG, BMP, JPG etc.. in OpenGL ES in Android. **Before you begin the code, you need to import your images into your project's /res/drawable/ folder. Just right click the project in eclipse and select import to do that.** //First setup the integer array to hold texture numbers which OpenGL generates int texture[] = new int[1]; //Generate and bind to the texture (gl is my GL10 object) gl.glGenTextures(1, texture, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); //Setup the texture co-ordinates float texCoords[] = { 0.0f, 0.0f, 1.0f, 0.0f,.......}; FloatBuffer texcoords = FloatBuffer.wrap(texCoords); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texcoords); Bitmap wood = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.myimagefilenamewithoutextension); //Setup optional texture parameters gl.gl...

Turning on Depth Buffer makes everything disappear !

I finally got to use textures on Android using OpenGL ES, and I found that its turn I started using the Depth buffer for some proper rendering. The moment I uncommented gl.glEnable(GL10.GL_DEPTH_BUFFER); The object disappeared and became invisible. Not even a pixel of the object was visible. Then a colleague of mine gave me a hint about clearing buffers ! Uffff ! I corrected the line "gl.glClear(GL10.GL_COLOR_BUFFER_BIT);" --to-- "gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);" and everything was fine again !