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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:43:01+00:00 2026-06-11T14:43:01+00:00

I am trying to draw 2 triangles together as a rectangle and draw the

  • 0

I am trying to draw 2 triangles together as a rectangle and draw the entire texture over it which I thought would just be 1.0 coordinates. I get 1 triangle with a lot of tiny faded textures. Im very new to opengl and kind of lost what is going on with these calls.
Does anyone see anything obviously wrong probably in my QUAD class like I have wrong coordinates or drawing in wrong order?

  public class MyRenderer implements GLSurfaceView.Renderer {
        private Quad myquad;
        private Context context;
        int texture[] = new int[1];
        private int width,height;
        int x,y;
        private long startframe,timediff,sleeptime,frameskip;
        private final static int MAX_FPS = 25;
        private final static int MAX_FRAME_SKIPS = 5;
        private final static int FRAME_PERIOD = 1000/MAX_FPS;
        private static Direction move_direction=Direction.NONE;


        public MyRenderer (Context context){
          this.myquad = new Quad();
          this.context = context;
        }
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            myquad.loadGLTexture(gl, this.context);

            //turn on alpha blending
            gl.glEnable(GL10.GL_BLEND);
            gl.glBlendFunc(gl.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

            gl.glEnable(GL10.GL_TEXTURE_2D);
            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
            gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
            gl.glDisable(GL10.GL_DEPTH_TEST);

            x=y=0;
        }

        public void onSurfaceChanged(GL10 gl, int w, int h) {
            width=w;
            height=h;
            gl.glViewport(0, 0, w, h);
            gl.glMatrixMode(GL10.GL_PROJECTION);    //Select The Projection Matrix          
            gl.glLoadIdentity();
            gl.glOrthof(0.0f, 320, 0.0f, 480, 1.0f, -1.0f);        
        }

        public void onDrawFrame(GL10 gl) {
            startframe=SystemClock.elapsedRealtime();
            // define the color we want to be displayed as the "clipping wall"
            gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            // clear the color buffer to show the ClearColor we called above...
            gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
          //  gl.glLoadIdentity(); 
            switch (move_direction)
            {
            case UP:
                gl.glTranslatef(0, 1, 0);
                y=y+1;
                break;
            case DOWN:
                gl.glTranslatef(0, -1, 0);
                y= y-1;
                break;
            case LEFT:
                gl.glTranslatef(-1, 0, 0);
                x=x-1;
                break;
            case RIGHT:
                gl.glTranslatef(1, 0, 0);
                x=x+1;
                break;
            case NONE:
                //gl.glTranslatef(0, 0, 0);
                break;
            }
            myquad.Draw(gl);

class Quad {
    private FloatBuffer vertices;
    private int[] textures = new int[1];
    private ShortBuffer indexbuffer;
    //private float vertices[] = {
    //      50.0f, 50.0f,  // 0. 
    //         100.0f, 50.0f,   // 1. 
    //        100.0f,  100.0f,   // 2. 
    //         50.0f,  100.0f // 3. 
    //};

    private float texture[] = {          
             0.0f, 0.0f,   //0
             1.0f, 0.0f,    //1
             1.0f, 1.0f,     //2
             1.0f, 0.0f        //3
    };

    private short indices[] = {0,1,2,0,3,2};



              public Quad(){
                try
            {
                    float[] coords={50.0f, 50.0f,  //0
                    300.0f,50.0f, //1
                    300.0f, 300.0f,  //2
                    300.0f, 50.0f}; //3

            short[] indices = {0,1,2,0,3,2};

            ByteBuffer verticesbuffer =     ByteBuffer.allocateDirect(coords.length*4);
            verticesbuffer.order(ByteOrder.nativeOrder());
            vertices = verticesbuffer.asFloatBuffer();
            vertices.put(coords);
            //vertices.position(0);
            vertices.flip(); 

        ByteBuffer idb = ByteBuffer.allocateDirect(indices.length * 2);
        idb.order(ByteOrder.nativeOrder());
        indexbuffer = idb.asShortBuffer();
        indexbuffer.put(indices);
        //indexbuffer.position(0);
        indexbuffer.flip();
        }catch(Exception e)
         {
            Log.d("buffers","not working",e);
         }
    }

     public void loadGLTexture(GL10 gl, Context context) {
          //Get the texture from the Android resource directory
          //Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.herowalkback);
         try
         {
         Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.herowalkback);

          if (bitmap == null) 
          {
              Log.i ("info", "bitmap could not be decoded");
          }
          //Generate one texture pointer...
          gl.glGenTextures(1, textures, 0);
          //...and bind it to our array
          gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

          //Create Nearest Filtered Texture
          gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
          gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);

          gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

          //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
          GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0,bitmap, 0);

          //Clean up
          bitmap.recycle();
         }catch(Exception e)
         {
            Log.d("load texture","not working");
         }
       }

    public void Draw(GL10 gl)
    {   
        // set the color for the triangle
        gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);

        //Enable the vertex and texture state
        vertices.position(0);
        gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertices);
        vertices.position(2);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, vertices);


        // Draw the vertices as triangle strip
        gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, indexbuffer);

    }
}


public class test extends Activity {
    private GLSurfaceView glsurface;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        glsurface = new GLSurfaceView(this);
        glsurface.setRenderer(new MyRenderer(this));
        setContentView(glsurface);
        glsurface.setOnKeyListener(watchkeys);
        glsurface.setFocusable(true);
        glsurface.setFocusableInTouchMode(true);


    }
  • 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-11T14:43:03+00:00Added an answer on June 11, 2026 at 2:43 pm

    You are not doing anything wrong. This is called texture mapping, you need to get used to this type of situations.

    So for example, remember that to map a triangle horizontally (the x coordinates) you used 0.0 and 1.0. With two triangles involved you need to divide the coordinate accordingly. So it is 0.0, 0.5, 1.0. And the same for the Y axis.

    Ideally you would use a modelling tool like Blender to texture map your objects, so you don’t worry about dividing 1.0 into an x number of triangles.

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

Sidebar

Related Questions

Just trying to get a triangle to draw to the screen, following a c++
I'm just trying to draw a line with JavaScript. I would like it to
I'm trying to draw a gradient, but first I just want to get the
I'm trying to draw a semi-transparent rectangle on top of an image to act
I am trying to draw over a canvas by clicking and dragging the mouse.
I'm trying to draw an open rectangle using a Polygon: int[] xPoints = {1,1,3,3};
I'm developing an iPhone app with 3.1.3 SDK. I'm trying to draw a triangle
I am trying to draw an MKPolygon (a triangle) on my mapview, but it
I am trying to animate a triangle when two triangles have been clicked twice.
I'm trying to draw a polygon using c# and directx All I get is

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.