user502656
user502656

Reputation: 1

Android: OpenGL texture and glDrawTexfOES problems

I've tried to follow all the information I could find, but I am not having any luck finding the source of my texture problems and could really use a hand.

The following is piece of code in which I'm trying to draw 3 pieces of my background using glDrawTexfOES. The 3 pieces should look like green grass.

public void onDrawFrame(GL10 gl) {

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();

    gl.glFrontFace(GL10.GL_CW);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, grass);

    gl.glColor4x(0x10000, 0x00000, 0x10000, 0x10000);

    ((GL11Ext) gl).glDrawTexfOES(0.0f, 0.0f, -8.0f, 32, 32);
    ((GL11Ext) gl).glDrawTexfOES(32.0f, 0.0f, -8.0f, 32, 32);
    ((GL11Ext) gl).glDrawTexfOES(64.0f, 0.0f, -8.0f, 32, 32);
}

Instead of green grass however, I'm getting 3 brown squares: http://img109.imageshack.us/img109/9670/84615249.jpg

Any help in figuring out why my textures won't display correctly would be most appreciated!

On a related note, for building a simple 2D tiled game is glDrawTexfOES the most efficient method for generating the tiled background?

Thanks in advance, Harry

Upvotes: 0

Views: 4614

Answers (2)

john
john

Reputation: 11

You need to define the mapping of the image to the rectangle You are probably just getting the top left pixel of the image.

int[]crop={0,0,text_dimx,text_dimy}; ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, crop,0);

Upvotes: 1

Ben Voigt
Ben Voigt

Reputation: 283684

If you google most OpenGL functions you get documentation for the function, followed by examples. For that function, the results are dominated by people having trouble.

That function might be slightly faster than using textures the usual way (I haven't used it so I don't know), but simply applying a texture to a quad needs no extensions and is extremely portable.

Why don't you try that and get back to us... it could be that the function is working perfectly, but something went wrong initializing the texture. Using the uncomplicated texture-a-quad method will help you find that out as well.

Upvotes: 0

Related Questions