Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:47:34+00:00 2026-05-26T09:47:34+00:00

I am work my game on android, using OpenGL developing 2D game, running on

  • 0

I am work my game on android, using OpenGL developing 2D game, running on 320×480 device was work.(no any broken)

Unfortunately issue on my motorola defy (480×854), seems like the adjust UV point object having 1-px diff(up or down 1 px position deviation).

SurfaceChanged return width 320,height 569
AndroidManifest anyDensity is setting false

Below two images have two rectangle, the left one is original image(w=36,h=35), no crop; middle one is clip by uv, draw from px1 and crop only width 34px,height 33px,right one very long rectangle, draw from top to bottom from px0 to px480 width 34px,height 1px, sorry for virtual code but you know what I means.

My previous game is written in SurfaceView, worked on 320×480, 480×800, 480×854 and 1024×768.

The picture look like work, width filled but bottom has biggest empty.

If I insert w=320; h=480; before GLUgluOrtho2D in SurfaceChanged,some object work(which not use crop by UV)

image1
http://i1105.photobucket.com/albums/h355/ch_mac/device_str5.png

The result I would like :

wantedresult
http://i1105.photobucket.com/albums/h355/ch_mac/device_str6.png

My texture drawing method :

public void draw(int from_x,int from_y,int w,int h,int pos_x,int pos_y)
{

          bind();
          float texW=(float)mPow2Width;  
          float texH=(float)mPow2Height;

          float minU= from_x/texW;
          float maxU = (from_x+w)/texW;        
          float minV= from_y/texH;        
          float maxV = (from_y+h)/texH;
           float verticleBuffer[] = {
               x,  y,
             x+w,  y,
               x, y+h,
             x+w, y+h,
           };
           float coordBuffer[] = {
            minU, minV,
            maxU, minV,
            minU, maxV,
            maxU, maxV, 
    };

FloatBuffer     m_vertexBuffer;
    FloatBuffer     m_textureBuffer;
    ByteBuffer l_byteBuf;
    l_byteBuf = ByteBuffer.allocateDirect( verticleBuffer.length * 4 );
    l_byteBuf.order( ByteOrder.nativeOrder() );
    m_vertexBuffer = l_byteBuf.asFloatBuffer();
    m_vertexBuffer.put( verticleBuffer );
    m_vertexBuffer.position( 0 );

    l_byteBuf = ByteBuffer.allocateDirect( coordBuffer.length * 4 );
    l_byteBuf.clear();
    l_byteBuf.order( ByteOrder.nativeOrder() );
    m_textureBuffer = l_byteBuf.asFloatBuffer();
    m_textureBuffer.put( coordBuffer );
    m_textureBuffer.position( 0 );

           gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, m_textureBuffer);
           gl.glVertexPointer(2, GL10.GL_FLOAT, 0, m_vertexBuffer);     
           gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0,4);

}

SurfaceChanged :

public void onSurfaceChanged(GL10 gl, int w, int h) 
{
    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    float aspect_w=(float)h/(float)w;
    float aspect_h=(float)w/(float)h;       
    //w=320;
    //h=480;
    GLU.gluOrtho2D(gl, 0, w, h, 0);

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:47:34+00:00Added an answer on May 26, 2026 at 9:47 am

    Place the viewport and projection setup in the drawing handler. It’s the only place where they actually make sense (like most other OpenGL operation). Doing those things somewhere else is a bookkeeping nightmare and gains no performance.


    EDIT: Another issue:

    float verticleBuffer[] = {
               x,  y,
             x+w,  y,
               x, y+h,
             x+w, y+h,
           };
    float coordBuffer[] = {
            minU, minV,
            maxU, minV,
            minU, maxV,
            maxU, maxV, 
    }
    

    Are you sure that coordBuffer is right? To me it looks like the last two lines are swappned, i.e. that one made more sense:

    float coordBuffer[] = {
            minU, minV,
            maxU, minV,
            maxU, maxV,
            minU, maxV, 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experimenting with writing a small game engine for Android using OpenGL ES.
I'm developing a game for android and this is my first experience with OpenGL.
Im developing a game for Android using AndEngine. As of now, I want to
I'm developing 2D Side scroll Android Game, using AndEngine and its BOX2D extension. I
I am using Unity3D to build an Android/iPhone game. I was happily C# scripting
I have a C++ game running through JNI in Android. The frame rate varies
I'm using XCode 3.2.6. I'd like to make my game work for earlier version
I am trying to make a simple pong game using opengl-es. I have checked
I'm trying to make an NDK-based game work on Android ICS. It worked fine
I made a game in C++ with OpenGL ES rendering and using OpenAL for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.