Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

First of all I know this is a duplicated question and I check out another questions but didn't helped! I'm trying to convert my android game from canvas system to the GL10. After lots of googling I decided to do that for performans. Anyway I tryed to build a class that loads and draws textures. The problem is textures showing up whole black over my blue screen. I'm not sure If I can draw texture without creating any mesh or something like that but this is what I'm trying to do. I'm only trying to draw 2D texture on their own sizes so I think no mesh needed. Here are my codes:

onSurfaceCreated

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        gl.glClearColor(0.0f, 0.0f, 1.0f, 0.2f);
        gl.glClearDepthf(1.0f);
        gl.glViewport(0, 0, 800,  480);

        gl.glShadeModel(GL10.GL_SMOOTH);
        gl.glEnable(GL10.GL_DEPTH_TEST);
        gl.glEnable(GL10.GL_TEXTURE_2D);
        gl.glDepthFunc(GL10.GL_LEQUAL);
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
        //gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
        gl.glLoadIdentity();
        // This is the class where I load and draw my textures.
        textureStorage = new TextureStorage(gl);
        //I'm loading a texture.      **CODE A TEXTURE LOADER**
        bgNightID  = textureStorage.Load(BitmapFactory.decodeResource(context.getResources(),R.drawable.bg_game));
        //This is where I load my units variables. Nothing to do with it.
        RenderingFunctions.InitUnits(this);
    }

onDrawFrame

@Override
public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    //gl.glTranslatef(0, 0, -4);
        **CODE B DRAWING**
        // bgNightID is the ID of texture was loaded.
        textureStorage.DrawTexture(bgNightID, 50,50,0,(short)4000,(short)638);
        // Drawing background right here which is shows up black. 
}

CODE A TEXTURE LOADER

public int glLoad( Bitmap bitmap ){
    if ( gl == null ){
        Log.e(TAG, "Failed to load resource.  Context/GL is NULL");return -1;
    }
    int textureName = -1;
    gl.glGenTextures(1, TexIDStorage, 0);
    textureName = TexIDStorage[0];

    Log.d(TAG, "Generated texture: " + textureName);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

    int error = gl.glGetError();
    if (error != GL10.GL_NO_ERROR){ 
        Log.e(TAG, "GL Texture Load Error: " + error);
    }else
        Log.d(TAG, "Loaded texture: " + textureName);
    return textureName;
}

CODE B DRAWING

public void DrawTexture(int TexutreID, float X, float Y, float Z, short Width, short Height){
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    //gl.glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, TexIDStorage[TexutreID]);
    ((GL11Ext) gl).glDrawTexfOES(X, Y, Z, Width, Height);
}

I'm totaly new to GL10 and can't figure out what is the problem and what is it I'm missing. So if anyone can help me that would be great. Thank you for givim time!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The problem was my image was not power of 2. like 512x512 or 512x2048. When I did this it worked.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.