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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:43:53+00:00 2026-06-16T16:43:53+00:00

I am creating a noob version clone of Minecraft. To begin with, i wanted

  • 0

I am creating a noob version clone of Minecraft. To begin with, i wanted to render a cube and add a specific texture to all sides to start. I have created a Block class that contains the vertices from input and has an output Function named RenderBlock to render the “Block” with the attached Texture.

Here is the Function that inputs 8 arrays representing 8 coordinates for the 8 vertices of the Block.

void Block::SetVertices(float UL[],float UR[],float ZR[],float ZL[],float UL2[],float           UR2[],float ZR2[],float ZL2[])
{
  Front_Square[1][1]=UL[1];
  Front_Square[1][2]=UL[2];
  Front_Square[1][3]=UL[3];
  std::cout << "Front Top Left Coordinates" << std::endl;    
  std::cout << Front_Square[1][1] << ","<<Front_Square[1][2] << "," << Front_Square[1][3] << std::endl;
  Front_Square[2][1]=UR[1];
  Front_Square[2][2]=UR[2];
  Front_Square[2][3]=UR[3];
  std::cout << "Front Top Right Coordinates" << std::endl;    
  std::cout << Front_Square[2][1] << ","<<Front_Square[2][2] << "," << Front_Square[2][3] << std::endl;
  Front_Square[3][1]=ZR[1];
  Front_Square[3][2]=ZR[2];
  Front_Square[3][3]=ZR[3];
  std::cout << "Front Bottom Right Coordinates" << std::endl;    
  std::cout << Front_Square[3][1] << ","<<Front_Square[3][2] << "," << Front_Square[3][3] << std::endl;
  Front_Square[4][1]=ZL[1];
  Front_Square[4][2]=ZL[2];
  Front_Square[4][3]=ZL[3];
  std::cout << "Front Bottom Left Coordinates" << std::endl;    
  std::cout << Front_Square[4][1] << ","<<Front_Square[4][2] << "," << Front_Square[4][3] << std::endl;
  //--------------BACK SQUARE------------------------------------------------------------------------------------------------------------------------//  
  Back_Square[1][1]=UL2[1];
  Back_Square[1][2]=UL2[2];
  Back_Square[1][3]=UL2[3];

  Back_Square[2][1]=UR2[1];
  Back_Square[2][2]=UR2[2];
  Back_Square[2][3]=UR2[3];

  Back_Square[3][1]=ZR2[1];
  Back_Square[3][2]=ZR2[2];
  Back_Square[3][3]=ZR2[3];

  Back_Square[4][1]=ZL2[1];
  Back_Square[4][2]=ZL2[2];
  Back_Square[4][3]=ZL2[3]; 
};

And here is the Function the renders the Block.

void Block::RenderBlock(const char*SideTexture)
{
 glEnable(GL_TEXTURE_2D);
 Tex[1]=loadTexture(SideTexture); 
 glBindTexture(GL_TEXTURE_2D, Tex[1]);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);  
 glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Front_Square[1][1],Front_Square[1][2],Front_Square[1][3]);//FTL
glTexCoord2f(1.0f, 1.0f); glVertex3f(Front_Square[2][1],Front_Square[2][2],Front_Square[2][3]);//FTR
glTexCoord2f(1.0f, 0.0f); glVertex3f(Front_Square[3][1],Front_Square[3][2],Front_Square[3][3]);//FBR
glTexCoord2f(0.0f, 0.0f); glVertex3f(Front_Square[4][1],Front_Square[4][2],Front_Square[4][3]);//FBL
     glEnd();

    glBindTexture(GL_TEXTURE_2D, Tex[1]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Back_Square[1][1],Back_Square[1][2],Back_Square[1][3]);//BTL
glTexCoord2f(1.0f, 1.0f); glVertex3f(Back_Square[2][1],Back_Square[2][2],Back_Square[2][3]);//BTR
glTexCoord2f(1.0f, 0.0f); glVertex3f(Back_Square[3][1],Back_Square[3][2],Back_Square[3][3]);//BBR
glTexCoord2f(0.0f, 0.0f); glVertex3f(Back_Square[4][1],Back_Square[4][2],Back_Square[4][3]);//BBL
     glEnd();


    glBindTexture(GL_TEXTURE_2D, Tex[1]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Back_Square[1][1],Back_Square[1][2],Back_Square[1][3]);//BTL
glTexCoord2f(1.0f, 1.0f); glVertex3f(Front_Square[1][1],Front_Square[1][2],Front_Square[1][3]);//FTL
glTexCoord2f(1.0f, 0.0f); glVertex3f(Front_Square[4][1],Front_Square[4][2],Front_Square[4][3]);//FBL
glTexCoord2f(0.0f, 0.0f); glVertex3f(Back_Square[4][1],Back_Square[4][2],Back_Square[4][3]);//BBL
     glEnd();

    glBindTexture(GL_TEXTURE_2D, Tex[1]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Back_Square[2][1],Back_Square[2][2],Back_Square[2][3]);//BTR
glTexCoord2f(1.0f, 1.0f); glVertex3f(Front_Square[2][1],Front_Square[2][2],Front_Square[2][3]);//FTR
glTexCoord2f(1.0f, 0.0f); glVertex3f(Front_Square[3][1],Front_Square[3][2],Front_Square[3][3]);//FBR
glTexCoord2f(0.0f, 0.0f); glVertex3f(Back_Square[3][1],Back_Square[3][2],Back_Square[3][3]);//BBR
     glEnd();

     glBindTexture(GL_TEXTURE_2D, Tex[1]);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Back_Square[4][1],Back_Square[4][2],Back_Square[4][3]);//BBL
glTexCoord2f(1.0f, 1.0f); glVertex3f(Back_Square[3][1],Back_Square[3][2],Back_Square[3][3]);//BBR
glTexCoord2f(1.0f, 0.0f); glVertex3f(Front_Square[3][1],Front_Square[3][2],Front_Square[3][3]);//FBR
glTexCoord2f(0.0f, 0.0f); glVertex3f(Front_Square[4][1],Front_Square[4][2],Front_Square[4][3]);//FBL
     glEnd();

    glBindTexture(GL_TEXTURE_2D, Tex[1]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Back_Square[1][1],Back_Square[1][2],Back_Square[1][3]);//BTL
glTexCoord2f(1.0f, 1.0f); glVertex3f(Back_Square[2][1],Back_Square[2][2],Back_Square[2][3]);//BTR
glTexCoord2f(1.0f, 0.0f); glVertex3f(Front_Square[2][1],Front_Square[2][2],Front_Square[2][3]);//FTR
glTexCoord2f(0.0f, 0.0f); glVertex3f(Front_Square[1][1],Front_Square[1][2],Front_Square[1][3]);//FTL
     glEnd();
    glDisable(GL_TEXTURE_2D);
     };

2 arrays for Blocks Dirt and Grass
Dirt

float TL[] = {0.0f,-1.0f,1.0f,0.0f};
float TR[] = {0.0f,1.0f,1.0f,0.0f};
float BR[] = {0.0f,1.0f,-1.0f,0.0f};
float BL[] = {0.0f,-1.0f,-1.0f,0.0f};
float TL2[] = {0.0f,-1.0f,1.0f,-2.0f};
float TR2[] = {0.0f,1.0f,1.0f,-2.0f};
float BR2[] = {0.0f,1.0f,-1.0f,-2.0f};
float BL2[] = {0.0f,-1.0f,-1.0f,-2.0f}

Grass

float DTL[] = {0.0f,-1.0f,1.0f+Grass_XChan,0.0f};
float DTR[] = {0.0f,1.0f,1.0f+Grass_XChan,0.0f};
float DBR[] = {0.0f,1.0f,-1.0f+Grass_XChan,0.0f};
float DBL[] = {0.0f,-1.0f,-1.0f+Grass_XChan,0.0f};
float DTL2[] = {0.0f,-1.0f,1.0f+Grass_XChan,-2.0f};
float DTR2[] = {0.0f,1.0f,1.0f+Grass_XChan,-2.0f};
float DBR2[] = {0.0f,1.0f,-1.0f+Grass_XChan,-2.0f};
float DBL2[] = {0.0f,-1.0f,-1.0f+Grass_XChan,-2.0f};

Sorry for long Code. Here is Main.cpp if you want to see it.

#include <GL/glut.h>
#include <iostream>
#include <assert.h>
#include <fstream>
#include "block.h"
using namespace std;
float positionX = 0.0f;
float positionY = 0.0f;
float positionZ = -4.0f;
float angle = 0.0f;
float RotX=0.01f;
float RotY=0.0f;
float RotZ=0.0f;
float Grass_XChan=2.0f;
float Grass_ZChan=-2.0f;
bool Render = true;
Block Dirt;
Block Grass;
float TL[] = {0.0f,-1.0f,1.0f,0.0f};
float TR[] = {0.0f,1.0f,1.0f,0.0f};
float BR[] = {0.0f,1.0f,-1.0f,0.0f};
float BL[] = {0.0f,-1.0f,-1.0f,0.0f};
float TL2[] = {0.0f,-1.0f,1.0f,-2.0f};
float TR2[] = {0.0f,1.0f,1.0f,-2.0f};
float BR2[] = {0.0f,1.0f,-1.0f,-2.0f};
float BL2[] = {0.0f,-1.0f,-1.0f,-2.0f};

float DTL[] = {0.0f,-1.0f,1.0f+Grass_XChan,0.0f};
float DTR[] = {0.0f,1.0f,1.0f+Grass_XChan,0.0f};
float DBR[] = {0.0f,1.0f,-1.0f+Grass_XChan,0.0f};
float DBL[] = {0.0f,-1.0f,-1.0f+Grass_XChan,0.0f};
float DTL2[] = {0.0f,-1.0f,1.0f+Grass_XChan,-2.0f};
float DTR2[] = {0.0f,1.0f,1.0f+Grass_XChan,-2.0f};
float DBR2[] = {0.0f,1.0f,-1.0f+Grass_XChan,-2.0f};
float DBL2[] = {0.0f,-1.0f,-1.0f+Grass_XChan,-2.0f};
void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(positionX, positionY, positionZ);
  glPushMatrix();
  glRotatef(angle,RotX,RotY,RotZ);
  Dirt.RenderBlock("C:/Users/Progr_Anim/Desktop/textures/DirtBottom.bmp");
  Grass.RenderBlock("C:/Users/Progr_Anim/Desktop/textures/GrassTop.bmp");

  glPopMatrix();
  glutSwapBuffers();
   }
  //-------------------------------------------------------------------------------------------------------------------------------------------
    void HandleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
   }
   void Camera(unsigned char key,int x,int y)
   {
   switch(key)
 {
  case 'w':
       positionZ += 0.08f;
       break;
  case 's':
       positionZ -= 0.08f;
       break;
  case 'a':
       positionX += 0.08f;
       break;
  case 'd':
       positionX -= 0.08f;
       break;
  case 'c':
       if(angle>=360.0f)
       {
       angle=0.0f;                
       }
       angle+=5.0f;
       break;
  case '1':
       angle = 0.0f;
       RotX=1.0f;
       RotY=0.0f;
       RotZ=0.0f;
       break;
  case '2':
       angle = 0.0f;
       RotX=0.0f;
       RotY=1.0f;
       RotZ=0.0f;
       break;
  case '3':
       angle = 0.0f;
       RotX=0.0f;
       RotY=0.0f;
       RotZ=1.0f;
       break;
  case 'q':
       exit(0);
       break;
     }     
  }
 int main(int argc, char** argv)
 {
   Dirt.SetVertices(TL,TR,BR,BL,TL2,TR2,BR2,BL2);
   Grass.SetVertices(DTL,DTR,DBR,DBL,DTL2,DTR2,DBR2,DBL2);
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
   //Create Window
   glutInitWindowSize(640,480);
   glutCreateWindow("Love");
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_COLOR_MATERIAL);
   glutDisplayFunc(display);
   glutReshapeFunc(HandleResize);
   glutKeyboardFunc(Camera);
   glutIdleFunc(display);
   glutMainLoop();
     return 0;
    }

Here is the video with the rotation cubes with the Grass block on Top and Dirt Block on the Bottom.
Link

  • 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-16T16:43:55+00:00Added an answer on June 16, 2026 at 4:43 pm

    I’m going to take a punt at an answer here, as I don’t think there’s quite enough information in the post.

    The arrays in this code are being used as if the 0th element does not exist, and the definitions of arrays used have an extra zero at the front as padding.

    However some arrays are not defined in the code here, and must be declared elsewhere, probably with a size. I’m going to guess at this size being wrong for a 1-indexed array.

    i.e. back_square and front_square are probably declared something like:

    float back_square[4][3];
    

    rather than:

    float back_square[5][4];
    

    which is how they are being used.

    The result will be undefined behaviour, which in this case is possibly the overwriting of a vertex, collapsing one corner of a cube.

    Either way, I would strongly recommend not using arrays in this fashion, and getting used to things starting at zero.

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

Sidebar

Related Questions

c#/oop noob here. I am creating a datatable from the schema of a sql
So I am creating a fading gallery and am a bit of a noob
Noob @ programming with python and pygtk. I'm creating an application which includes a
I'm creating trips in my rails app and i want to add categories to
I'm following a tutorial for creating an animation using Xcode Version 4.5.2 in Mountain
Noob here and I have 2 questions. 1) When creating an array like this
I'm a total noob at Android programming, and wanted to learn how to debug
I'm a noob to android and I am having trouble creating entries and retrieving
Creating simple app using GAE / Django-nonrel (I don't think the problem is specific
This is quite a noob question, so please bear with me. I am creating

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.