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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:50:52+00:00 2026-06-05T03:50:52+00:00

I started drawing hexagonal grid on canvas with Path object. I did all the

  • 0

I started drawing hexagonal grid on canvas with Path object. I did all the calculations on how many hexagons go on a particular display, depending on the hexagon size.

I have all my hexagon coordinates calculated depending on canvas. But now, I have serious performance issues and have to port this to OpenGL.

Because the algorithm works in canvas, I’m trying to convert those “canvas” hexagon coordinates to OpenGL coordinate system with GLU.gluUnProject.

“for loop”

float near[] = { 0.0f, 0.0f, 0.0f, 0.0f };
            GLU.gluUnProject(b.hexes[ii][jj].points[ii].x,
                    b.hexes[ii][jj].points[ii].y, 0, mg.mModelView, 0,
                    mg.mProjection, 0, viewport, 0, near, 0);
vertices[zz] = (float) ((near[0])/near[3]);
            zz++;
            vertices[zz] = (float) ((near[1])/near[3]);
            zz++;
            vertices[zz] = 0;

Because I lack opengl knowledge, I dont know how to set glViewport,gluPerspective,glTranslatef to 2D world that is “the same” as canvas.

So my question is:

How to set those three thing that my first hexagon (on canvas, the first one is top left) to be equal on openGL drawing surface world?

Update

Thank you all for you’re interest of helping on my problem. But:

I now set my 18 float vertices array as follows:
[20.0, 0.0, 0.0, 60.0, 0.0, 0.0, 80.0, 34.641018, 0.0, 60.0, 69.282036, 0.0, 20.0, 69.282036, 0.0, 0.0, 34.641018, 0.0]
Z is always 0.

ByteBuffer vertexByteBuffer = ByteBuffer
                .allocateDirect(vertices.length * 4);
vertexByteBuffer.order(ByteOrder.nativeOrder());
vertexBuffer = vertexByteBuffer.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);

and draw:

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, vertices.length/3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

Before draw I set:
onDrawFrame()

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -5.0f);

onSurfaceChanged()

gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0, width, height, 0, -1, 1); 
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-06-05T03:50:54+00:00Added an answer on June 5, 2026 at 3:50 am

    You have no need to transform yourself the vertices coordinates. All you have to do is to provide the correct projection matrix to OpenGL.

    Basically, this would be something along the lines of :

    glViewport(0, 0, canvasWidth, canvasHeight);
    glMatrixMode(GL_PROJECTION);                     // or some matrix uniform if using shaders
    glLoadIdentity();
    glOrtho(0, canvasWidth, canvasHeight, 0, -1, 1); // this will allow to pass vertices in 'canvas pixel' coordinates
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    

    Depending on the order in which you’re passing your vertices, you might want to make that culling is disabled.

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

Sidebar

Related Questions

I've just started coding video games and I've heard that doing all your drawing
I'm working on a custom Swing Component for my application, and I started drawing
I have started developing a drawing application in as3. I am thinking that I
Where can I get started drawing animated geometry in C#? I would like to
I've just started iOS drawing programming and I found out that the coordinate system
I want to display my game on the screen. I started to write a
First of all I'm new to the C# world. I just started this year
So I have just started working with HTML5 and the Canvas element. I'm working
I started learning today 3D drawing, following this tut: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/The_first_triangle.php There is the file
A couple of days ago I started looking into efficiently drawing bezier curves, and

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.