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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:37:08+00:00 2026-05-12T17:37:08+00:00

This is a homework question I am sorry but I am lost. What happens

  • 0

This is a homework question I am sorry but I am lost. What happens is the following I am asked to do a tiling of hexagons. Like the grid map in many Risk games and Wild Arms XF. I understand the current transformation is the matrix that translates the points I give to OpenGL to screen coordinates and if you apply a transformation it moves the the center point usually (0,0) to wherever.

If you use glPushMatrix and glPopMatrix. What it does is make a replica of the current CT matrix and you do operations on it and when you pop it you return to the matrix without the transformation.

The problem is the following I am trying to draw a hexagon, Translate(Displace, I like it better), draw another Hexagon, translate and Draw the last hexagon. What happens is the third hexagon dissapears from the face of the viewport and I am only raising it twice. What is funny is that consecutive rotates and scales give me no problems.

so a small sample of the code.

#include <windows.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <iostream>
#include <ctime>
using namespace std;

void initCT(void)
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void drawHexagon()
{
    glBegin(GL_LINE_STRIP);
       glVertex2i(0,0);   
       glVertex2i(20, 0);
       glVertex2i(25,10);
       glVertex2i(20,20);
       glVertex2i(0,20);
       glVertex2i(-5,10);
       glVertex2i(0,0);
    glEnd();
}

void myInit(void)
{
    initCT();
    glClearColor(1.0f,1.0f,1.0f,0.0f);
    glColor3f(0.0f, 0.0f, 0.0f);   //set the drawin color
    glPointSize(1.0);   //a 'dot'is 4 by 4 pixel
        glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluOrtho2D(-100.0, 400.0, -400.0, 400.0);
    glViewport(0, 0, 640, 480); 
}

void myDisplay (void) {
    glClear (GL_COLOR_BUFFER_BIT);
    glMatrixMode( GL_MODELVIEW );
    drawHexagon();
    glTranslated(0.0f,20.0f,1.0f);
    drawHexagon();
    glTranslated(0.0f,20.0f,1.0f);
    drawHexagon();
    glTranslated(0.0f,20.0f,1.0f);
    drawHexagon();

    glFlush();    //send all output to display
}

void main (int argc, char **argv) {
    glutInit (&argc, argv); 
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize (640, 480); 
    glutInitWindowPosition (100, 150); 
    glutCreateWindow ("Hexagon Tiling"); 
    glutDisplayFunc (myDisplay); 
    myInit();

    glutMainLoop(); 
}

I have used this code with the similar result, only two hexagons draw the others go into the Hitchhikers guide to the galaxy. I changed the colors of each hexagon and only the first two appear.

THANK YOU GUYS YOU ARE THE MEN. I am sorry if giving the answer to one upsets the other but you both are right.

Also for people using Google this is from Computer Graphics using Open GL there is an error in the translation function that the author gives you in the translate it should be 0 in the Z axis.

  • 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-12T17:37:08+00:00Added an answer on May 12, 2026 at 5:37 pm

    You’re translating behind the camera; Each translation goes up in the y axis by 20, and in the z axis by 1. After the second step, your hexagons are behind the camera, and can’t be seen in the viewport.

    Try

    glTranslated(0.0f,20.0f,0.0f);
    

    for each translation; that should help.

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

Sidebar

Related Questions

This is a homework question, but I think there's something missing from it. It
This is a homework question, I got the basics down, but I can't seem
yes, this is a homework-type question but could you please help me out? In
This is a homework question, so I would like to avoid complete answers and
This is a homework question, and I'm asked to show that 8 element Binary
This is not a homework question, but rather my intention to know if this
This is a homework question, but as you can see I've written most of
This isn't strictly a homework question, but an offshoot. How are time functions implemented
this is a homework question, and I'm not that at finding the complixity but
For starters this is a homework question. I have an idea but I am

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.