简体   繁体   English

使用MFC Visual Studio的C ++电子游戏

[英]Video Game on C++ with MFC visual studio

I don't know if I had gotten it all wrong, so I'm asking for directions here. 我不知道自己是否弄错了,所以我在这里问路。

Let's take for example, back in college, when you learned C++ and used Turbo C++ or GCC to compile, you get an idea of what a low level programming language is. 例如,回到大学时,当您学习C ++并使用Turbo C ++或GCC进行编译时,您将了解什么是低级编程语言。

Now let's say I want to make a basic 2D video game, just as a personal project, nothing fancy, and I want to develop it using C++ just because. 现在,让我们说我想制作一个基本的2D视频游戏,就像一个个人项目一样,没什么花哨的,而我想使用C ++来开发它。 I'd code it using Visual Studio since it's a pretty good IDE. 我会使用Visual Studio对其进行编码,因为它是一个非常不错的IDE。

Is it right to say "I'm going to use MFC" for this kind of project? 在这类项目中说“我要使用MFC”是否正确? (Consider the fact that I'd be using OpenGL). (考虑一下我将使用OpenGL的事实)。

MFC is a C++ framework that encapsulates the core elements of the Windows API. MFC是一个C ++框架,封装了Windows API的核心元素。 It's primarily intended for creating standard, windowed applications that the user interacts with on the desktop. 主要用于创建用户在桌面上与之交互的标准窗口应用程序。

It comes with a built-in graphics framework: GDI. 它带有一个内置的图形框架:GDI。 The one that was introduced with Windows, revolutionary for its time because it abstracted away hardware-specific details and allowed programmers to write general code that ran on any machine Windows ran on. Windows引入的那个,在当时具有革命性意义,因为它抽象了硬件特定的细节,并允许程序员编写在Windows运行的任何计算机上运行的通用代码。 But it was never particularly good for games; 但这对游戏从来都不是特别好。 it was designed for Windows-style business applications. 它是为Windows风格的业务应用程序设计的。 It was awesome for text (and is still arguably the best option that there is—have you looked at how Direct2D renders text lately?), and handled simple graphics, but consider that before alternative graphics-specialized frameworks like OpenGL were available, most game developers stuck with DOS, where they could/were forced to interact directly with the graphics hardware at a low level. 它对文本很棒(并且可以说仍然是最好的选择,您最近看过Direct2D渲染文本的方式吗?),并且处理了简单的图形,但是考虑到在使用诸如OpenGL之类的可选图形专用框架之前,大多数游戏开发人员坚持使用DOS,他们可能/被迫直接与底层的图形硬件进行交互。

So if you want to use MFC and OpenGL together, you can , but I don't really see the point. 因此,如果您同时使用MFC和OpenGL, 可以使用 ,但是我并不明白这一点。 The only real benefit you'd be gaining from MFC is a reduction of 100-some-odd lines of code that sets up the fundamental skeleton of any Windows application. 您将从MFC中获得的唯一真正的好处是减少了100多条代码,这些代码设置了任何Windows应用程序的基本框架。 For example, considering this sample OpenGL program , using MFC would essentially allow the WinMain and the MainWndProc functions to be buried deep in the bowels of the MFC framework code, rather than appearing directly in your code. 例如, 考虑此示例OpenGL程序 ,使用MFC实际上将允许WinMainMainWndProc函数被深埋在MFC框架代码的内部,而不是直接出现在您的代码中。 But, like I said, big deal. 但是,就像我说的那样,很重要。 The majority of your code is going to be OpenGL-specific, and MFC won't help there. 您的大多数代码将是OpenGL特定的,而MFC在此方面将无济于事。

The only way it might make sense for the two to interact is if you wrote the launchpad/host for the game using MFC and GDI (ie, the part that displays windows and dialogs on screen), and then the game portion itself in OpenGL (launched once you clicked a "Start" button on the dialog interface). 两者进行交互的唯一途径是,如果您使用MFC和GDI(即在屏幕上显示窗口和对话框的部分)编写了游戏的启动板/主机,然后使用OpenGL(单击对话框界面上的“开始”按钮启动。

And of course, even if you wanted to do this, MFC is not your only option. 当然,即使您想这样做,MFC也不是唯一的选择。 There are tons of C++ frameworks for writing Windows applications. 有大量用于编写Windows应用程序的C ++框架。 Everyone has their favorite. 每个人都有自己的最爱。 Despite what some may tell you, there's nothing wrong with MFC if you already know it and/or are comfortable with the Windows API. 尽管有人可能会告诉您,但如果您已经知道MFC和/或对Windows API感到满意,则MFC没什么问题 But don't waste time learning it. 但是不要浪费时间学习它。 Use WTL instead. 请改用WTL

You would NOT use MFC simply because it is meant for general application development giving you features and classes that you will most likely never use! 您不会仅仅因为MFC就是为了进行常规应用程序开发而使用MFC,从而为您提供您极有可能不会使用的功能和类!

A good start would be to look at SFML http://www.sfml-dev.org/ or (my personal favourite) SDL http://www.libsdl.org/ . 一个好的开始是查看SFML http://www.sfml-dev.org/或(我个人最喜欢的)SDL http://www.libsdl.org/ These libraries were written to develop games or at least multimedia applications using them. 编写这些库是为了开发游戏或至少使用它们的多媒体应用程序。

Writing a Game Editor in MFC can be a good idea though! 在MFC中编写游戏编辑器可能是一个好主意!

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

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