3D Battle Network Game C + + framework based on C/s architecture _03 Client detail design with OpenGL, QT Basics

Source: Internet
Author: User

This series of blog mainly on the background of the game to introduce 3D PvP Network game Common Development technology and C + + advanced programming skills, with this knowledge, you can develop small and medium-sized game projects or 3D industrial simulation projects.

The author will be divided into the following three sections to introduce to you (daily update):

1, the realization of the basic communication framework, including the game needs analysis, design and development environment and the construction of communication framework;

2, the implementation of the network underlying operations, including the creation of thread pool, serialization network packets, etc.;

3, actual combat drills, to achieve similar to the CS counter-Strike 3D Battle Network game;

Technical points: C + + Object oriented thinking, network programming, QT interface Development, QT control knowledge, boost smart pointers, STL algorithm, STL, container, boost network library, OpenGL coordinate transformation, OpenGL load 3D model, MD2 model loading, MDL model loading

OK, let's start today's learning journey, today we will be the client's detailed design, with everyone familiar with OpenGL knowledge and use and QT related knowledge and applications, in order to further study and research, this game framework of the client I did not choose to use Cocos, Unity, UE and other game engine directly to make, but chose Qt and OpenGL, the unity engine for real game development interested in the follow-up will be published by my other blog, thank you for your support ~.

First, the OpenGL Foundation

(1) What is OpenGL:

OpenGL is a set of application programming interfaces (APIs) that enable our developers to open programs that have the ability to access graphics hardware. We can use OpenGL to develop more efficient graphics programs or games, because OpenGL is very close to the underlying hardware and OpenGL makes it unnecessary for us to focus on the details of the graphics hardware. Since we developers don't have to focus on the details of graphics hardware, what do we need to focus on? We need to focus on how OpenGL is drawn, using a virtual camera and light to generate an image of the object in terms of its specifications and related attributes. OpenGL programs are independent of the platform, so the OpenGL API does not contain any input functions or window functions because both functions depend on specific platforms, such as Windows,linux or other systems.

OpenGL APIs are procedural, not descriptive, that OpenGL is not object-oriented, so OpenGL cannot take advantage of object-oriented features such as overloading, inheritance, etc., but we can use object-oriented programs to link to OpenGL implementations. As a developer, we do not need to describe the nature and appearance of the scene, but to determine some of the operating procedures for the implementation of certain graphics or images to serve. We can implement these steps by invoking some of the commands in OpenGL, which can be used to draw points, lines, polygons, or other graphics, and to invoke these commands to achieve various effects such as lighting, coloring, animation, and so on.

The implementation of OpenGL can be either a software implementation or a hardware implementation. A software implementation is a library of functions that respond to a OPENGGL function call and create a two-or three-dimensional image, then the hardware is implemented by setting up a graphics card driver that can draw graphics or images. In general, hardware implementations are much faster than software implementations. We should all be familiar with the graphical device interface on Windows that displays graphics or images on the screen or on other display devices. OpenGL implementation in terms of software implementation, the Windows will be based on the requirements of the program commands to generate the corresponding graphics or images, then the graphics or images will be handed over to the graphics device interface, the graphics device interface to display graphics or images on our screen or other display devices. That said, we might understand that a little bit of openggl turned out to be working between the application and the graphics device interface, but I don't feel like it's accurate. Let's look at the following diagram. The working principle of OpenGL may be understood more clearly:

  

Is how OpenGL's software implementation works. It is important to note that the structure of the graph is constructed by software.

OpenGL hardware implementation is slightly different from the software implementation, the hardware implementation is to pass OpenGL calls to the hardware driver, and the hardware driver does not pass the generated graphics or images to the graphics device interface, but directly with the display device communication, Pass graphics or image results directly to a display or other display device. As shown in the following:

OpenGL is based on a pattern known as the pipelining model when drawing graphics. In other words, the geometry in the program specifies its shape and is generated by the program by describing the space position or vertex, which, when flowing through a series of modules, implements one or more operations on the basic component of the graph, which is called an entity here. The module is responsible for implementing one or more operations transformations on the elements that flow through, such as rotation, panning, zooming, and positioning the camera.

(2) The composition of OpenGL

OpenGL contains many functions for graphics image processing, including the following:

Primitive functions: Specifies the entities to generate graphics or images. There are two main types, one is to draw two-dimensional or three-dimensional geometric elements, such as points, lines, polygons, etc., the other is a discrete entity, for example: Bitmap.

Property functions: Property functions are mainly to control the appearance and style of the elements, such as: the color of the elements, line style, lighting and texture effects processing.

Observation function: The observation function is mainly the operation of camera properties. We can operate the camera to display graphics or images in close proximity or long distance effects.

Control function: Allows us to enable or to the various OpenGL features.

Query function: Allows us to query the values of OpenGL state variables.

Input and window control functions: This does not belong to OpenGL in itself, but since we often enter output or window control operations in the program, these functions are more important.

second, QT Foundation

(1) What is QT:
QT is a cross-platform C + + graphical user interface application framework developed by the 1991 technology. It provides all the functionality that application developers need to build an art-level graphical user interface. QT is easy to scale and allows for real component programming. Basically, Qt is the same type of thing as the MOTIF,OPENWIN,GTK on the X Window and the Mfc,owl,vcl,atl on the Windows platform.

(2) Why QT selection:

1. Support major mainstream desktop operating systems: Mac, Windows, Linux
2. Provide a large number of libraries: XML, database, thread, network, container, smart pointer, regular, OpenGL, etc.
3.c++ development, execution speed is much faster than Java and C #
4. Exemplary Development Documentation
5. Support LGPL free license
6. Fast and practical UI designer
7. Single root inheritance and meta-object system, which make up some shortcomings of C + +
8. Beautiful interface, clear code, is one of the most beautiful C + + libraries
9. Powerful memory management

third, the game client design

(1) Thinking:

Based on the previous analysis and design of the client, how do we make a detailed design of the client?

(2) class diagram:

Four, 3D scene module design

(1) Thinking:

Based on the display requirements of the 3D interface and the interface requirements of the 3D scene module, what aspects should be considered for the detailed design of the module?

(2) class diagram:

Welcome everyone to learn to communicate, if there is insufficient to criticize correct, reproduced please indicate the source, thank you for your support. If you also like my blog can continue to follow me, let us grow together and progress together.

Life is wonderful. Remove impurities, leaving the search for the poor pole of programming pure pursuit.

3D Battle Network game based on C/S architecture C + + Framework _03 client detail design with OpenGL, QT Basics

Related Article

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.