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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:11:10+00:00 2026-05-15T12:11:10+00:00

I’m looking to draw a cube at specific co-ordinates. I’ve got all 4 corners

  • 0

I’m looking to draw a cube at specific co-ordinates. I’ve got all 4 corners and the centers x/y value. I now want to construct a cube at those co-ordinates. Does anyone know of any tutorials or have any information on how I would go about said task?

Ive got the following code. I’d like to map each of its corners to a specific x/y co-ord

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;

 class GLCube {
    private final IntBuffer mVertexBuffer;


  private final IntBuffer mTextureBuffer;


   public GLCube() {

  int one = 65536;
  int half = one / 2;
  int vertices[] = {
        // FRONT
        -half, -half, half, half, -half, half,
        -half, half, half, half, half, half,
        // BACK
        -half, -half, -half, -half, half, -half,
        half, -half, -half, half, half, -half,
        // LEFT
        -half, -half, half, -half, half, half,
        -half, -half, -half, -half, half, -half,
        // RIGHT
        half, -half, -half, half, half, -half,
        half, -half, half, half, half, half,
        // TOP
        -half, half, half, half, half, half,
        -half, half, -half, half, half, -half,
        // BOTTOM
        -half, -half, half, -half, -half, -half,
        half, -half, half, half, -half, -half, };



  int texCoords[] = {
        // FRONT
        0, one, one, one, 0, 0, one, 0,
        // BACK
        one, one, one, 0, 0, one, 0, 0,
        // LEFT
        one, one, one, 0, 0, one, 0, 0,
        // RIGHT
        one, one, one, 0, 0, one, 0, 0,
        // TOP
        one, 0, 0, 0, one, one, 0, one,
        // BOTTOM
        0, 0, 0, one, one, 0, one, one, };



  // Buffers to be passed to gl*Pointer() functions must be
  // direct, i.e., they must be placed on the native heap
  // where the garbage collector cannot move them.
  //
  // Buffers with multi-byte data types (e.g., short, int,
  // float) must have their byte order set to native order
  ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
  vbb.order(ByteOrder.nativeOrder());
  mVertexBuffer = vbb.asIntBuffer();
  mVertexBuffer.put(vertices);
  mVertexBuffer.position(0);



  // ...
  ByteBuffer tbb = ByteBuffer.allocateDirect(texCoords.length * 4);
  tbb.order(ByteOrder.nativeOrder());
  mTextureBuffer = tbb.asIntBuffer();
  mTextureBuffer.put(texCoords);
  mTextureBuffer.position(0);

 }


 public void draw(GL10 gl) {
  gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);


  gl.glEnable(GL10.GL_TEXTURE_2D); // workaround bug 3623
  gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, mTextureBuffer);



  gl.glColor4f(1, 1, 1, 1);
  gl.glNormal3f(0, 0, 1);
  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
  gl.glNormal3f(0, 0, -1);
  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);

  gl.glColor4f(1, 1, 1, 1);
  gl.glNormal3f(-1, 0, 0);
  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4);
  gl.glNormal3f(1, 0, 0);
  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4);

  gl.glColor4f(1, 1, 1, 1);
  gl.glNormal3f(0, 1, 0);
  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4);
  gl.glNormal3f(0, -1, 0);
  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4);
 }


  static void loadTexture(GL10 gl, Context context, int resource) {
  Bitmap bmp = BitmapFactory.decodeResource(
        context.getResources(), resource);
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
  gl.glTexParameterx(GL10.GL_TEXTURE_2D,
        GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
  gl.glTexParameterx(GL10.GL_TEXTURE_2D,
        GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  bmp.recycle();
 }

}
  • 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-15T12:11:11+00:00Added an answer on May 15, 2026 at 12:11 pm

    if you just want to translate your cube to x y coordinate use

    gl.glTranslatef(x, y, 0);
    

    before drawing it.

    this is a tutorial for opengl transformations in android.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.