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

  • SEARCH
  • Home
  • 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 8920957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:24:40+00:00 2026-06-15T06:24:40+00:00

Alright so this is going to be a doozy to explain. I’m making a

  • 0

Alright so this is going to be a doozy to explain. I’m making a very basic “pseudo-3d” racing game for Android using AndEngine (and in turn, openGL – I think). I don’t believe using AndEngine really has anything to do with this problem though, because I’m directly accessing openGL functions to accomplish my drawing.

Anyways, I copy-pasta’d some code that allowed the normally 2d AndEngine to have a 3d perspective (tutorial for such can be found here. This works pretty well, and I also don’t believe this has much to do with my problem, but I don’t fully understand openGL so it’s a little hard for me to say. Here’s the code from the onLoadEngine (called when app starts) that sets up the camera with a 3d perspective:

this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT) {
    //other methods...
    private void setFrustum(GL10 pGL) {
        // set field of view to 60 degrees
        float fov_degrees = 60;
        float fov_radians = fov_degrees / 180 * (float)Math.PI;                        

        // set aspect ratio and distance of the screen
        float aspect = this.getWidth() / (this.getHeight());
        float camZ = this.getHeight()/2 / (float)Math.tan(fov_radians/2);                              

        // set projection
        GLHelper.setProjectionIdentityMatrix(pGL);
        GLU.gluPerspective(pGL, fov_degrees, aspect, camZ/10, camZ*10); 

        // set view
        GLU.gluLookAt(pGL, 0,120f, camZ, 0, 0, 0f, 0, 1, 0); // move camera back+up
        pGL.glScalef(1,-1,1); // reverse y-axis
        pGL.glTranslatef(-CAMERA_WIDTH/2,-CAMERA_HEIGHT/2,0); // origin at top left
    }
};

Then later in the onLoadScene (where the drawing takes place), I draw a bunch of my images like so:

for (int n=0;n<=100;n++) {
    final int k = n;

    final Sprite line = new Sprite(0, 0,CAMERA_WIDTH,16f, [AndEngine texture holding road img]) {
    @Override
        protected void applyTranslation(GL10 pGL) {
            pGL.glTranslatef(this.mX, 120f, 15f*k); //16*k causes a sliver of a space between each segment
            pGL.glRotatef(90f, 1, 0, 0); //**MAY BE MY ISSUE**
        }           
    };
    scene.attachChild(line); //actually draws the image to the screen           
}

Which works pretty darn well as well, except for one thing! It distorts the shit out of my images. The images are simple pngs, both matching the CAMERA_WIDTH, and both looking similar to this:
"road" segment - 320 x 16

And when I draw it without the rotate line, I get this:
without the rotating

Which has a decently straight middle line (tbh I’d be happy with them this way), but then you can see the edges of the road are all facing basically the exact opposite way they should be facing. I figured why not just flip them? I thought I would have to rotate them 180 degrees around the x axis, but instead that just makes them disappear, and instead I found that 90 degrees works (???). Anyways, Here’s what I get:

final product

So yeah. Here’s where my problem lies – the middle lane divider is distorted as crap!! The lines marking the edge of the road line up wonderfully, but for whatever reason its really messing with that middle line. I get most of the math behind the 3d, but I really don’t know what to make of this…it’s almost like the image is being compressed because its being viewed at such a sharp angle, but I don’t really know how the hell I could solve that without simply making it a top-down view? :S

Anyways… any ideas or guidance is welcome. Sorry this is such a long and convoluted post – it makes it hard when I really have no idea where the problem lies.

Also – It might be worth noting I have little to no experience with openGL or 3d graphics, and have even less interest in learning much about them in depth. I need a band-aid to this problem!

  • 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-06-15T06:24:42+00:00Added an answer on June 15, 2026 at 6:24 am

    Ok so I found the solution! Turns out there is this little issue called Perspective Correct Texturing, that is basically just a flag that needs to be turned on in OpenGL to make it not skew images when they are being drawn with perspective.

    Inside my Camera initializing code, I added this line to the method setFrustum(GL10 pGL):

    pGL.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    

    That this essentially solved the problem. Lines are as straight as ever now 🙂 I found this out on another stackoverflow post where this answer actually wasn’t what the asker wanted, but it just so happened to work for me 😀 The thread that led me to the answer can be found here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm going to try to explain this as best as possible: I have
Alright, this is a very simple question. I just installed Tomcat 6 on my
Alright, this may take a moment or two to explain: I'm working on creating
Alright, so this is something really basic, and I know that when someone tells
Alright this is a really weird one so I am going to layout what
Alright, maybe I am going around this wrong. We shall see. So there is
Alright, Im going about this, with what is probably a really complicated solution, but
Alright, I am going to state up front that this question may be too
Alright, this is basic c++ here. I've got a class that is a Linear
Alright, this is a bit hard to explain, and therefore a bit hard to

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.