Jump to content
  • Advertisement
Sign in to follow this  
Yasaswi Srikanth

OpenGL Bloxorz game in OpenGL.

This topic is 2324 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi friends,

I am trying to develop the Bloxorz game in OpenGL.
Please see this link http://www.albinoblacksheep.com/games/bloxorz

To do that I have draw the squares floor and a rectangle on top of it.
By I have trouble starting this. I mean I can't figure out how can I draw the floor like in 3d and a rectangular cube thing.

Please guide me.
I have googled this item , but haven't got anything.

Share this post


Link to post
Share on other sites
Advertisement
Draw a 2d grid flat over the whole screen. Rotate it on the x-axis by 45 degrees, then 45 degrees on the y-axis. You now have a 3d game board.

To start, write some code, make a grid draw it etc.

Share this post


Link to post
Share on other sites
The http://nehe.gamedev.net/ . Yes I have seen them.
Do you mean the Legacy Tutorials?
I think these are very old like in 2000 . Will it be still useful for beginners in OpenGL to follow them?

Share this post


Link to post
Share on other sites

The http://nehe.gamedev.net/ . Yes I have seen them.
Do you mean the Legacy Tutorials?
I think these are very old like in 2000 . Will it be still useful for beginners in OpenGL to follow them?


Yes, those are the ones that I meant. Yes, it got originated in early 2000's, but will remain useful for another century or so. It will teach you fundamentals of 3D programming which does not change within a decade.

Share this post


Link to post
Share on other sites
Hi , I want to design the floor of the bloxorz game in photoshop. is it a good idea to design the entire floor as one bmp file and load it ? If so I don't know how to create this floor in photoshop. can anyone please guide me?

Share this post


Link to post
Share on other sites
No, you should create 1 tile only. Then you can have a level editor / map file to load where you have the empty spots and spots with tiles. Otherwise you have a giant bitmap with no sense of "What is the x,y,z position of tile 1, tile 2" you dont know because all you have is a single bitmap holding tons of tiles.

If this is causing you this much trouble, try doing something else. Or at least start with creating and loading a 2d map of tiles. For instance, back in the day me/classmates used to design tiles by loading a text file. X meant blank space, O meant a tile. Load this into a 2D array.
Map.txt
oxxooo
ooooo
xxooo
xxxoo

for(int i = 0;.......)
{
for(int j = 0;.......)
if(board[j] == x){//don't do anything, no tile}
if(board[j] == o){//draw the regular tile at position x = i, y = j)

Share this post


Link to post
Share on other sites
hello ,

Thanks dpadam450 for the answer.
I have some how managed to draw the floor and a block on it. by taking two functions like this :

drawFloor present in Floor class outside main :

void Floor::drawFloor()
{



glRotatef(45.5f,1.0f,1.0f,0.0f);

//Draw floor
for(int i = 1;i<6;i++)
{


for(int j = 1;j<6;j++)
{

//For hole to appear at 3,3
if(i == 3 && j==3)
{
glTranslatef(1.0f,0.0f,0.0f);
continue;
}


glBegin(GL_QUADS);

// Top Face
glColor3f(1.0f,0.0f,0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.500f,0.500f,-0.500f); //top left
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.500f,0.500f,0.500f); //bottom left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.500f,0.50f,0.50f); //bottom right
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f,0.50f,-0.50f);//top right

//Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.50f, 0.50f, -0.50f); //Top front
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f, 0.30f, -0.50f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.50f, 0.30f, 0.50f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.50f, 0.50f, 0.50f);

// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.50f,0.50f, 0.50f); //top right
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,0.50f,0.50f); // top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.50f,0.30f, 0.50f); //bottom left
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.50f,0.30f, 0.50f); //bottom right


// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f,0.30f,0.50f); // top right
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.50f,0.30f,0.50f); // top left
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.50f,0.30f,-0.50f); // bottom left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.50f,0.30f, -0.50f); //bottom right



// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,0.50f,-0.50f); // top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.50f, 0.50f,-0.50f); //top right
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.50f, 0.30f,-0.50f); //bottom right
glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.50f,0.30f, -0.50f);//bottom left




// Right face

glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.50f, 0.50f, -0.50f); // Top right
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f, 0.50f, 0.50f); // top left
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.50f, 0.30f, 0.50f); //bottom right
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.50f, 0.30f, -0.50f); //bottom left



glEnd();

glTranslatef(1.0f,0.0f,0.0f);


}
glTranslatef(-5.0f,0.0f,-1.0f);

}

drawCube present in Cube class :

void Cube::drawCube()
{


glBegin(GL_QUADS);

// Top Face
glColor3f(0.0f,1.0f,0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.500f,0.500f,-0.500f); //top left
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.500f,0.500f,0.500f); //bottom left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.500f,0.50f,0.50f); //bottom right
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f,0.50f,-0.50f);//top right


//Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.50f, 0.50f, -0.50f); //Top right
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,-0.5f, -0.50f); //top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.50f,-0.5f, 0.50f); //bottom left
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.50f, 0.50f, 0.50f); //bottom right

// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.50f,0.50f, 0.50f); //top right
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,0.50f,0.50f); // top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.50f,-0.5f, 0.50f); //bottom left
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.50f,-0.5f, 0.5f); //bottom right


// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f,-0.50f,0.50f); // top right
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.50f,-0.50f,0.50f); // top left
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.50f,-0.50f,-0.50f); // bottom left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.50f,-0.50f, -0.50f); //bottom right



// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,0.50f,-0.50f); // top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.50f, 0.50f,-0.50f); //top right
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.50f,-0.50f,-0.50f); //bottom right
glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.50f,-0.50f, -0.50f);//bottom left




// Right face

glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.50f, 0.50f, -0.50f); // Top left
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f, 0.50f, 0.50f); // bottom left
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.50f, -0.50f, 0.50f); //bottom right
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.50f, -0.5f, -0.50f); //top right



glEnd();


}


I have placed the hole at 3,3 position look on drawing floor.
My main problem is moving the block left and right . For that I have taken a structure called

typedef struct
{
public:

float x_pos;
float y_pos;
float z_pos;
float radian;
}cube_param;

I created an object like cube_param cube_pos;
while left key is pressed :

case WM_KEYDOWN: // Is A Key Being Held Down?
{
keys[wParam] = TRUE; // If So, Mark It As TRUE

switch(wParam)
{
case VK_LEFT:
{

cube_pos.x_pos = - 1.0f ;
cube_pos.y_pos = -1.0f;
cube_pos.z_pos = 0.0f;
cube_pos.radian = -90.0f;

cube->drawCube(cube_pos);



}
}

return 0;



}

where drawCube(cube_pos); contains the same code as drawCube() but it has to move it.
Here does the structure cube_pos goes away with values to drawCube(cube_param cube_pos)

Look at it :

// For movement of cube
void Cube::drawCube(cube_param cube_pos)
{



float x_pos = cube_pos.x_pos;
float y_pos = cube_pos.y_pos;
float z_pos = cube_pos.z_pos;
float radian = cube_pos.radian;


//glTranslatef(1.0f,1.0f,0.0f);


glRotatef(radian,x_pos,0.0f,0.0f);


glBegin(GL_QUADS);

// Top Face
glColor3f(0.0f,1.0f,0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f + x_pos,0.5f + y_pos,-0.5f); //top left
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f + x_pos,0.5f + y_pos,0.5f); //bottom left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f + x_pos,0.5f + y_pos,0.5f); //bottom right
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f + x_pos,0.5f + y_pos,-0.5f);//top right


//Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.50f, 0.50f, -0.50f); //Top right
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,-0.5f, -0.50f); //top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.50f,-0.5f, 0.50f); //bottom left
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.50f, 0.50f, 0.50f); //bottom right

// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.50f,0.50f, 0.50f); //top right
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,0.50f,0.50f); // top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.50f,-0.5f, 0.50f); //bottom left
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.50f,-0.5f, 0.5f); //bottom right


// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f,-0.50f,0.50f); // top right
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.50f,-0.50f,0.50f); // top left
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.50f,-0.50f,-0.50f); // bottom left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.50f,-0.50f, -0.50f); //bottom right



// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.50f,0.50f,-0.50f); // top left
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.50f, 0.50f,-0.50f); //top right
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.50f,-0.50f,-0.50f); //bottom right
glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.50f,-0.50f, -0.50f);//bottom left




// Right face

glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.50f, 0.50f, -0.50f); // Top left
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.50f, 0.50f, 0.50f); // bottom left
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.50f, -0.50f, 0.50f); //bottom right
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.50f, -0.5f, -0.50f); //top right



glEnd();




}


My idea is when left key is pressed i want to translate each and every vertex by adding or subtracting the x_pos,y_pos,z_pos present in cube_param structure
and then translate and rotate it. will it ultimately work for each and every move ?
If so how to do it. Edited by Yasaswi Srikanth

Share this post


Link to post
Share on other sites
before you get into a point when you want to move certain object try to create some structure around your code. Instead of hundrets glVertex(...) glTexCoords(...) with hardcoded numbers in those create some easy to use functions that would accept a position as an input and internally would call OpenGL functions to render your objects. Further it would be easier for you to change things upon user action.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!