我想使用 openGL 制作一个简单的 3D 游戏,我应该从哪里开始?

发布于 2024-08-06 04:26:44 字数 263 浏览 2 评论 0原文

我发现通过榜样我学得最好。是否有一个好的网站或代码库可以展示事件处理、碰撞检测、建模和基本 3D 绘图的工作原理?

我尝试开始的游戏是一个简单的赛车游戏,用户控制一艘小型太空飞船并穿过通道、小行星带、太空殖民地和各种其他障碍(我知道,真正的原创)。运动是三维的。游戏应该知道航天飞机何时撞到障碍物。与大多数赛车游戏中一样,有定义的赛道(赛道和线性路径)。

按箭头键应该会导致方向矢量适当旋转。此外,例如,当用户按下空格键时,飞船应该使用加力燃烧室之类的东西。上下移动也是一种选择。

I find that I learn best by example. Is there a good website or codebase that shows how event handling, collision detection, modeling, and basic 3D drawing works?

The game I'm trying to begin with is a simple racing game where the user controls a small space ship and navigates through channels, asteroid fields, space colonies, and various other obstacles (I know, real original). Movement is in 3 dimensions. The game should know when the shuttle hit an obstacle. There are defined tracks as there are in most racing games (circuits and linear paths).

Pressing the arrow keys should cause the direction vector to rotate appropriately. Also, the ship should use something like an afterburner when the user presses the space bar, for example. Movement up and down is also an option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

心不设防 2024-08-13 04:26:44

如果你想学习OpenGL,我建议从“OpenGL红皮书”开始,然后查看 NeHe 的样本。红皮书至少在线 HTML 格式是免费的,还有可下载的 PDF。

不过红皮书和NeHe主要教你如何使用OpenGL;编写游戏是一门艺术,有太多的东西需要解释,太多的东西需要学习,太多的东西需要阅读。这只是一个提示。

这是大多数游戏的基本结构。希望它对基础知识有所帮助。当然,这不是一个完整的游戏,不会运行,并且很大程度上取决于你如何做事,但它应该给你一个基本的想法。

void update(float k)
{
  // k == time in seconds since last update; e.g. 0.02
  ship.y += ship.speed_y*k;
}
int main()
{
   while(1)
   {
      if(hasEvents())
      {
        event_t evt;
        getEvent(&evt);
        if (evt.type == keypress && evt.key==down) 
        {
           ship.speed_y=1;
        }
      }
      paint();
      new_ticks = get_ticks();
      update((new_ticks - old_ticks)/1000.);
      old_ticks = new_ticks;
   }
}

If you want to learn OpenGL, I recommend starting with "OpenGL Red Book", and then looking at NeHe's samples. Red Book is free at least in online HTML format, there are also downloadable PDFs around.

However, Red Book and NeHe will teach you mostly how to use OpenGL; writing games is art, and there's far too much to explain, far too much to learn, and far too much to read about it. Here's just a tip.

This is basic structure of most games. Hopefully it helps with basics. Of course it's not a full game, won't run, and greatly depends on how you do things, but it should give you a basic idea.

void update(float k)
{
  // k == time in seconds since last update; e.g. 0.02
  ship.y += ship.speed_y*k;
}
int main()
{
   while(1)
   {
      if(hasEvents())
      {
        event_t evt;
        getEvent(&evt);
        if (evt.type == keypress && evt.key==down) 
        {
           ship.speed_y=1;
        }
      }
      paint();
      new_ticks = get_ticks();
      update((new_ticks - old_ticks)/1000.);
      old_ticks = new_ticks;
   }
}
提笔落墨 2024-08-13 04:26:44

由于不知道您的初始技能水平,我建议您看一下 Ogre3D。它是一个完整的 3D 渲染引擎,具有非常干净的界面,易于扩展,最重要的是,它可以在 Windows、Linux 和 Mac OS X 上运行的多平台。提供的示例和教程非常不言自明。

如果您想完全从头开始编写自己的纯 OpenGL 引擎,Ogre3D 可能不是您可以遵循的路径...

Not knowing your initial skill level I suggest you taking a look at Ogre3D. It is a complete 3D-rendering engine that has really clean interface to work with, easy to extend and best of all, it's quite multiplatform working on Windows, Linux and Mac OS X. The examples and tutorials provided are pretty self-explaining.

If you want to write your own OpenGL-only engine completely from scratch, Ogre3D may not be the path to follow...

離人涙 2024-08-13 04:26:44

一些注释,其中一些已经说明:

  • OpenGL 红皮书。一个很好的起点。这本书已经过多次修订,因此相比之下,免费的在线版本有点过时了。
  • GameDev.net。对于所有经验的开发人员来说,它们是一个极好的资源,并且论坛上有很多才华横溢的人。他们回答了这个问题:“我想制作一款游戏,从哪里开始?”很多很多很多次。
  • 我不推荐NeHe。我发现那里的教程常常会让新手感到困惑。这些教程展示了“如何”,但很少解释关键的原因

游戏开发是一个庞大的多方面学科。即使您拥有非常扎实的数学和编程技能,这也是具有挑战性的。

两条建议:

  • 从小事做起。从小处开始。从小处开始。您可能认为您的目标相当温和,但它涉及的内容比您想象的要多得多。
  • 避免剪切和粘贴示例代码的诱惑。你会欺骗自己失去重要的理解。

A couple of notes, some of which have already been stated:

  • The OpenGL Redbook. An excellent place to start. The book has seen several revisions, so the free online version is a bit dated by comparison.
  • GameDev.net. They are a wonderful resource for developers of all experience, and they have a lot of talented people on the forums. They have answered the question, "I want to make a game, where do I start?" many, many times.
  • I do not recommend NeHe. I find that the tutorials there, more often than not, confuse a neophyte. The tutorials show "how", but do very little to explain the crucial why.

Game development is a huge multifaceted discipline. It's challenging even if you have very solid math and programming skills.

Two pieces of advice:

  • Start small. Start small. Start small. You might think your goal is pretty modest, but it will involve a great deal more than you imagine.
  • Avoid the temptation to cut and paste example code. You will cheat yourself out of crucial understanding.
吻风 2024-08-13 04:26:44

NeHe

这个网站在我学习 opengl 时对我的帮助最大。

NeHe

This site helped more then anything when I was learning opengl.

人疚 2024-08-13 04:26:44

我必须对使用nehe发出警告,因为很多人都推荐了它。(抱歉,没有帐户发表评论)

主要是因为它只展示了如何使用固定管道而不是着色器来执行操作。前几个教程可能可以帮助您开始了解如何在屏幕上显示某些内容。但是,不要浪费时间来学习如何激活 alpha 混合和为固定管道设置照明,因为如果你想做一些看起来不像 1999 年游戏的事情,你将不得不重新学习如何做再次使用所有这些东西,但是使用着色器。我认为最好从一开始就学习新方法。

I must give a warning for using nehe because many people have recommended it.(don't have an account to make comments, sorry)

Mainly because it only shows how to do things with the fixed pipeline instead of shaders. The first couple of tutorials might be ok the get a kickstart of how to get something on the screen. But don't waste your time with for example learning how to activate alpha blending and setting up lighting for the fixed pipeline, because if you want to do something that doesn't look like a game from 1999 you will have to relearn how to do all that stuff again but with shaders. Better to learn the new way from the beginning imo.

草莓酥 2024-08-13 04:26:44

首先,我不建议您在第一个游戏中使用 OpenGL,特别是如果您以前从未编程过。您应该强烈考虑更新且更简单的方法,例如使用 C# 的 XNA。

其次,和OpenGL一样,XNA在网上也有大量的教程,相信你会发现非常有帮助。

如果您以前从未进行过编程,我建议您作为起始项目,应该尝试创建一个非常简单的游戏,例如 Pong 或 Tic Tac Toe。我认为您总体上会对游戏开发有很好的感觉。从那里,您可以根据创建 Pong 所获得的经验开始实际项目。

最后,当你冒险探索时,我可以给你的主要建议是,无论你在创建游戏时遇到什么障碍,都不要放弃。

祝你好运! ^^

Firstly, I don't recommend using OpenGL for your first game, especially if you've never programmed before. You should strongly consider the newer and easier methods like XNA with C#.

Secondly, like OpenGL, XNA also has a large number of tutorials on the Internet, which I believe you will find very helpful.

If you've never done programming before, I recommend as a starting project, you should try creating a very simple game like Pong, or Tic Tac Toe. I think you will get a good feel of game development in general. From there, you can start on your actual project from the experience you've gained by creating Pong.

Lastly, the main piece of advice I can give you as you adventure on your quest is to never give up no matter what obstacles you face in creating your game.

Good Luck! ^^

Smile简单爱 2024-08-13 04:26:44

我不知道你有多少游戏编程经验,但我会从一些更有限的东西开始。

从基于 2d 图块的游戏(推箱子等)开始 - 它们相对容易编写 - 对象始终精确地位于图块上,这使得事情变得非常简单。

一旦你掌握了游戏循环、计时、处理用户输入、数据模型、渲染器等原则,那么你就可以做一些更复杂的事情。

然后你可以尝试像“小行星”这样的东西,它需要一些二维向量数学,建模惯性(即积分)可能需要一点三角函数。以及基于非图块的碰撞系统。

一旦你掌握了这一点,那么你就可以尝试一些 3D 的东西 - 这使得事情在数学方面再次变得更加复杂。

I've no idea how much game programming experience you have, but I'd start with something a bit more limited.

Start with a 2d tile-based game (Sokoban etc) - they're relatively easy to write - something where the objects are always exactly on a tile, that makes things pretty trivial.

Once you've got the principles of that, game loop, timing, processing user input, data model, renderer etc, then you can do something more involved.

Then you can try something like "Asteroids" which is going to need some 2d vector maths, modelling intertia (i.e. integration) possibly a bit of trig. and a non-tile based collision system.

Once you've got that licked, then you can try something 3d - which makes things more complicated again, maths-wise.

挽梦忆笙歌 2024-08-13 04:26:44

我会在 www.gamedev.net 上四处看看,它包含一些针对初学者的优秀教程,在论坛中,您将找到与游戏编程相关的任何主题的大量信息。

I would look around on www.gamedev.net, it contains some excellent tutorials for beginners and in the forums you'll find a great deal of information on any subject related to games programming.

懒猫 2024-08-13 04:26:44

首先,您应该考虑代码的结构。每个游戏都会有以下一些变化:

int main()
{
   Screen::Init();
   Game::Init();

   while (Game::isrunning)
   {
      Game::Update();
      Screen::Render();
   }

   Game::Shutdown();

   return 0;
}

其余的只是实现细节。尝试查看 SDL,它可以处理 Windows 编程中的许多令人讨厌的事情(初始化窗口、加载 OpenGL 等),因此您可以专注于编写游戏。

First, you should think about the structure of your code. Every game ever has some variation of the following:

int main()
{
   Screen::Init();
   Game::Init();

   while (Game::isrunning)
   {
      Game::Update();
      Screen::Render();
   }

   Game::Shutdown();

   return 0;
}

The rest just becomes an implementation detail. Try looking at SDL, it handles a lot of the nasty things of Windows programming (initializing a window, loading OpenGL, etc.) so you can focus on writing your game.

浪荡不羁 2024-08-13 04:26:44

是的,网上查一下教程。是的,请访问 GameDev.net。是的,NeHe 很混乱,而且很专业。

对于 OpenGL,我会结合 OpenGL SuperBible 的能力,让人们了解 OpenGL 的背景和可能性通过良好的老式谷歌搜索。

认识可以时常帮助您的人也很有帮助。 GameDev.net 有聊天室,人们很友好。

Yes, look up tutorials online. Yes, hang out at GameDev.net. Yes, NeHe is confusing and specialized.

For OpenGL, I would combine the OpenGL SuperBible's ability to make one aware of the context and possibilities of OpenGL with a good old-fashioned Google search.

It also helps to know someone who can help you out from time to time. GameDev.net has chatrooms and the people are friendly.

世俗缘 2024-08-13 04:26:44

如果你想要 opengl 但又想要 python 的简单性 - 首先了解 API 的原理可能会很好 - 请查看包装器: http://pyopengl.sourceforge.net/

它们与最新版本的 opengl 兼容,并且开发相当活跃。

If you want opengl but with the simplicity of python - which could be nice to understand the principle of the API at first - check out the wrappers : http://pyopengl.sourceforge.net/

They are compatible with the latest version of opengl and their development is quite active.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文