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 4592348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:31:34+00:00 2026-05-21T22:31:34+00:00

I have drawn one line having vertices (0.2f, 0.2f, 0.0f) & (-0.2f, -0.2f, 0.0f)

  • 0

I have drawn one line having vertices (0.2f, 0.2f, 0.0f) & (-0.2f, -0.2f, 0.0f) in OpenGL. As z component of line co-ordinates is missing it implies that line is in XY plane. Now i am trying to rotate the line around the z axis using glRotatef function. Ideally line rotation should have taken a circular path(at least it should have looked like a circle when rotated it by 1 to 360) but somehow it is looking more like a ellipse, more stretched towards y-axis (my guess is that, may be because of depth effect). but as my line is completely in XY plane(As Z component is missing in line co-ordinates) why am i getting such depth effect? I have posted my code herewith this question. Please point me to the right direction?

GLSurfaceViewActivity code file:

package com.mobi.trials.gldemo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class GLSurfaceViewActivity extends Activity {

SimpleGLSurfaceView glView = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i("GLDemo", "In the activity");
    glView = new SimpleGLSurfaceView(this);
    setContentView(glView);
}

@Override
protected void onPause() {
    super.onPause();
    glView.onPause();
}

@Override
protected void onResume() {
    super.onResume();
    glView.onResume();
}

}

SimpleGLSurfaceView code file:

package com.mobi.trials.gldemo;

import android.content.Context;
import android.opengl.GLSurfaceView;

public class SimpleGLSurfaceView extends GLSurfaceView {

public SimpleGLSurfaceView(Context context) {
    super(context);
    final DrawGLSurfaceCanvasView renderer = new DrawGLSurfaceCanvasView(this);

    setFocusable(true);
    setFocusableInTouchMode(true);
    setRenderer(renderer);
}

}

DrawGLSurfaceCanvasView code file:

package com.mobi.trials.gldemo;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;

public class DrawGLSurfaceCanvasView implements GLSurfaceView.Renderer {

SimpleLine line;
private float rotationAngle = 0.0f;
float lineVertices[] = {  0.2f, 0.2f, 0f,
          -0.2f, -0.2f, 0f };

public DrawGLSurfaceCanvasView(GLSurfaceView view) {
}

@Override
public void onDrawFrame(GL10 gl) {

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

    gl.glRotatef(rotationAngle, 0.0f, 0.0f, 1.0f);

    if(rotationAngle <= -360.0f)
    {
        rotationAngle = 0.0f;
    }
    rotationAngle -= 1f;

    line.draw(gl);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    line = new SimpleLine(lineVertices);
}

}

SimpleLine code file :

package com.mobi.trials.gldemo;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

public class SimpleLine {
float vertices[];
private FloatBuffer vertexBuffer;

public SimpleLine(float[] vertices) {
    super();
    this.vertices = vertices;
}

public void draw(GL10 gl)
{
    ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
    vbb.order(ByteOrder.nativeOrder());
    vertexBuffer = vbb.asFloatBuffer();
    vertexBuffer.put(vertices);
    vertexBuffer.position(0);

    // Update : Added orthographic projection matrix.
    // Update II : Corrected the values of orthgraphic projection matrix.
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glDrawArrays(GL10.GL_LINES, 0, 2);
}

}

  • 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-21T22:31:35+00:00Added an answer on May 21, 2026 at 10:31 pm

    I don’t think what you’re observing is a depth effect. It’s just that you did not set any projection matrix (resulting in picking up the default: the identity). So with a modelview matrix set as identity, you end up with [-1:1] representing the extents of your window.

    [-.2,.2] ends up representing 20% of your window. I assume your window is not square, so you end up drawing an ellipse with an eccentricity of your aspect ratio.

    You need to look at tutorials that explain how the projection matrix is typically set (it typically involves the size of your window and or its aspect ratio).

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

Sidebar

Related Questions

I have an OpenGL program that works on all of my computers but one.
My aim is to have a picture drawn on one device to be duplicated
I have drawn an object on NSView subclass. How can the object know that
I have a MyCanvas class that extends JComponent. On this canvas I have drawn
I have one piece of Cocoa code I wrote that takes in an XML
How would one go about achieving a line that will connect two rectangles together?
I have an activity that shows customer information. All the controls are drawn dynamically
I am using OpenGL/GLUT to implement Bresenham's line drawing algorithm and having some issues
I have one line segment formed by two vectors, let's say v1 and v2,
I have a Line class composed of two Points of two ints each that

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.