How to Develop Web 3D games

Source: Internet
Author: User
Tags unique id

Recently, a 3D Web Game emerged on the Internet, because it gave me a new understanding of some of the challenges on the web page, this gave me the idea to study.

To create a 3D Game On a webpage, you need to consider the following technical issues:

  • Web plug-in implementation
    Are there any obstacles for users to install plug-ins?
    How to draw 3D images in the plug-in
    How to connect to the server
    How to cache art resources
    How to update art resources
    Browser compatibility

This article is part of the answer to these questions and provides specific implementation solutions.

 

ActiveX plug-in technology

 

Currently, there are a lot of plug-ins in browsers, but there are not many popular plug-ins. In the past, due to browser plug-in security issues, most people were very cautious about plug-ins.

ActiveX is a browser plug-in technology provided by Microsoft. It is described on the Wiki at http://zh.wikipedia.org/wiki/activex. It is difficult for me to figure out the relationship between several technologies provided by Microsoft over the years, such as Ole and ALT, including the latest. net. To learn about Microsoft's framework, it takes a lot of time to understand the concept. In addition, the Code is complicated, which is far less direct and clear than the open-source technology.

I am using vs2005 to create an "MFC ActiveX Control" project.

Based on the wizard, it will automatically help you create a project with the extension name OCX. To debug and run the program, you need to modify the project properties to "ActiveX control test container", for example:

This is a tool used to load ActiveX controls. After debugging the interface, you need to manually click the menu: Edit-> Insert a new control and find the OCX plug-in you created. Or other tools ).

After you insert it once, remember to save it. Next time you can find the session you saved in the most recent open file menu.

So far, you can use the framework of MFC to add various functions provided by MFC, such as window, message, and event processing. If you have learned direct3d or OpenGL, you have the ability to add relevant code to this empty MFC project and run your own demo.

 

Integrated 3D engine: irrlicht

 

The goal of this article is to develop 3D games. Naturally, it is impossible to start from the graphic API. I found irrlicht, an open-source engine, as far as I know, there is already a successful commercial project developed by this engine in China, which means it is quite mature. About the engine you can visit the official website: http://irrlicht.sourceforge.net/

Now you can integrate into other engines, wiki: Game Engine list http://zh.wikipedia.org/wiki/%E6%B8%B8%E6%88%8F%E5%BC%95%E6%93%8E%E5%88%97%E8%A1%A8

The irrlicht engine is friendly and has no problems during compilation. Remember, read the document carefully and read the README files in various directories. This is a good habit for programmers.

I use static compilation here. After correct compilation, there will be directories corresponding to different compilers under the irrlicht directory/bin/lib/, which contains compiled lib files. Generally, two versions are generated: irrlicht_d.lib and release: irrlicht. Lib. I will use different lib files to compile plug-ins of different versions.

Next, configure the plug-in project again. This is critical! Add a pre-processor definition _ irr_static_lib _ to the "pre-processor" attribute page under "C/C ++ _.

 

Configure the input static Link Library, and configure irrlicht_d.lib and irrlicht for debug and release respectively. lib (of course, you need to set the global directory of vs2005 before, ensure that irrlicht. lib and irrlicht_d.lib files can be found ):

Then, based on the irrlicht examples and documents, you can add the relevant code when drawing the control and draw the 3D image into the MFC control. There is an engine document under the irrlicht directory/Doc. the first page of the document contains an example of the shortest size (I'm amazed at the designers of irrlicht, the interface is very friendly and cross-platform ).

The code in the example can be referenced but cannot be used, because it is in the framework of MFC. MFC is message-driven, while general 3D games require continuous loops to promote image rendering. This requires you to solve the problem of the draw loop. I have referred to some methods on the Internet and established an endless loop thread, which will push the rendering.

In my project, I created a class named gameframe to make the game logic layer and the external integration layer, so that the game logic does not need to know the environment in which it runs. The initialization of the game logic layer and the drive of the main loop are provided by the gameframe class.

For the structure of the gameframe class, see the header file:

The init and update interfaces are the most basic, including the game logic code. You can call setdc to set the DC and window handle, and trigger the init function in setdc. In addition, the external uses createupdatethread to start the draw cycle and call update cyclically to drive the game logic.

 

Create HTML pages for testing

 

I have not considered compatibility for the moment, but I just provided a simple example. (This part is enough for me to write an article)

We can see that <Object>

The key in this label is to define the classid. The specific content of this ID is the Globally Unique id of your control. vs2005 has automatically generated it for you. Press CTRL in the project name. the "initialize class factory and guid" under the CPP file.

 

If your plug-in has been registered, open the IE browser and you will be able to see what you have drawn.

 

 

Project File Download: http://download.csdn.net/source/3244642

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.