简体   繁体   English

在opengl中创建3d游戏表面/游戏板-C ++

[英]create a 3d playing surface/game board in opengl- c++

I am trying to create a 3D box, that would play the role of a playing board/surface/room for a 3D game in C++, using OpenGl. 我正在尝试使用OpenGl创建一个3D盒子,该盒子将充当C ++中3D游戏的棋盘/表面/房间。 As a starting point I found some code that does that for a 2D surface. 作为起点,我找到了一些针对2D表面的代码。 My question would be how to modify the following code to serve my purpose: 我的问题是如何修改以下代码以达到我的目的:

for (float  i = -width; i + 0.1 <= width; i += 0.1) {
    for (float j = -height; j + 0.1 <= height; j+= 0.1) {
        glBegin(GL_QUADS);

        glNormal3f(0, 1, 0);
        glVertex3f(i, 0, j);
        glVertex3f(i, 0, j + 0.1);
        glVertex3f(i + 0.1, 0, j + 0.1);
        glVertex3f(i + 0.1, 0, j);

        glEnd();
    }
}

Thanks a lot. 非常感谢。

You can either use above code 6 times but each time apply different rotation/translation matrix, or you can do it the right way and generate correct geometry for missing 5 walls of your box. 您可以使用上面的代码6次,但是每次都应用不同的旋转/平移矩阵,或者可以以正确的方式进行操作,并为缺少的5面墙生成正确的几何形状。 There are lots of samples for drawing cubes, ie.: 有很多用于绘制立方体的示例,即:

http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM