Jump to content
  • Advertisement
Sign in to follow this  
zi_jaz

OpenGL design building using OpenGL

This topic is 4778 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! Im new in OpenGL with C++.. just started to learn yet have to do a game. I need some help on how to design a building out of GL_QUADS with a front view. The front face of building is removed, and there will be 12 floors in the building. I am doing this game project which is to improve on a game and I have chosen Elevator Action Game to be modified.(if u ever heard of this arcade game) Basically this is a simple code that I have develop to make a long rectangular QUAD: //Using this 'drawn' QUAD, how to loop them to make 12 floors apart from each other from top to below with a gap between the floors at least 20.0 y-axis apart. void CDice::DrawSelf() { glPushMatrix(); glTranslatef(-100,y,z); glRotatef(yaw, 0.0f, 5.0f, 0.0f); glRotatef(pitch, 1.0f, 0.0f, 0.0f); glRotatef(roll, 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); //////////////////////// //Front face glColor3f(255,0,0); glVertex3f(-90.5,-10.5,10.5); glVertex3f(280.5,-10.5,10.5); glVertex3f(280.5,0,10.5); glVertex3f(-90.5,0,10.5); //////////////////////// //Right face glColor3f(0,255,0); glVertex3f(280.5,-10.5,10.5); glVertex3f(280.5,-10.5,-10.5); glVertex3f(280.5,0,-10.5); glVertex3f(280.5,0,10.5); //////////////////////// //Back face glColor3f(0,0,255); glVertex3f(280.5,-10.5,-10.5); glVertex3f(-90.5,-10.5,-10.5); glVertex3f(-90.5,0,-10.5); glVertex3f(280.5,0,-10.5); //////////////////////// //Left face glColor3f(255,255,0); glVertex3f(-90.5,-10.5,-10.5); glVertex3f(-90.5,-10.5,10.5); glVertex3f(-90.5,0,10.5); glVertex3f(-90.5,0,-10.5); //////////////////////// //Top face glColor3f(255,255,255); glVertex3f(-90.5,0.5,10.5); glVertex3f(280.5,0,10.5); glVertex3f(280.5,0,-10.5); glVertex3f(-90.5,0,-10.5); //////////////////////// //Bottom face glColor3f(255,0,255); glVertex3f(-90.5,-10.5,-10.5); glVertex3f(280.5,-10.5,-10.5); glVertex3f(280.5,-10.5,10.5); glVertex3f(-90.5,-10.5,10.5); glEnd(); glPopMatrix(); ///////////////////////////////////////////////////////////////////////// //while below is the SetupRC() void SetupRC() { glEnable(GL_DEPTH_TEST); // Hidden surface removal //glEnable(GL_CULL_FACE); // Do not calculate inside of jet glFrontFace(GL_CW); // Counter clock-wise polygons face out SetupLights(); // Nice light blue glClearColor(0.0f, 0.1f, 0.5f,0.4f); //create our camera; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,100, 0,0,-10, 0,1,0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(130,1,0.3,1000); glMatrixMode(GL_MODELVIEW); }

Share this post


Link to post
Share on other sites
Advertisement
In my opinion you walk the wrong way. It might be better if you learn how to render arbitrary meshes exported from 3d modellers like blender and so on. You could use a suitable format like md2 or anything else and write an import method for your engine. When that works, learn more about collision detection in order to make your game entities interact with your environment.

Since your are a newbie in game development this may sound very complex to you but it's the right way on the long run.

I have learned a lot from the book "OpenGL Game Programming". IMHO it's the perfect starting point for beginners.

Share this post


Link to post
Share on other sites
or simply create a display list with the box! :)



int Box;

Box = glGenLists(1);
glNewList(Box,GL_COMPILE);
//.. Your cube drawing code here, NOT rotations or transformations!!
glEndList();


then in your game do this:

//translate
//rotate
glCallList(Box);

}




call the Box everytime you need a box drawn, scale it if you need a bigger/smaller one..


cheers!

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!