Creating a video game using windows.h windows api

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 1574 Views - Last Post: 29 January 2020 - 07:48 AM Rate Topic: *---- 1 Votes

#1 Thunderer   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 132
  • Joined: 25-June 17

Creating a video game using windows.h windows api

Posted 05 September 2019 - 01:28 AM

How should I render images in windows API. Should I use setpixel. How to take input like mouse and keyboard. Please give some code. Currently my computer is broken. I am planning my game in notebook. Speed is necessary. I will be having an array of pixel and display it on the screen.

This post has been edited by Thunderer: 05 September 2019 - 04:12 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a video game using windows.h windows api

#2 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2414
  • View blog
  • Posts: 4,546
  • Joined: 30-May 10

Re: Creating a video game using windows.h windows api

Posted 05 September 2019 - 06:16 AM

> Speed is necessary.
Mmm, so you want to use an API that was never designed for games, to run on hardware that was never designed for games, and you want "speed is necessary".

Look at the kinds of games that come with Windows, like solitaire.
Not much moves, and not much moves very often or very fast.

Familiarise yourself with all the functions on offer, not just one.
https://docs.microso...n32/api/wingdi/

If you're wanting 60 frames a second full screen first person shooter, then you need DirectX or OpenGL/Vulkan and a beefed up GPU.
Was This Post Helpful? 1
  • +
  • -

#3 Thunderer   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 132
  • Joined: 25-June 17

Re: Creating a video game using windows.h windows api

Posted 05 September 2019 - 08:47 AM

How to know how much time elapsed since the program started?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15496
  • View blog
  • Posts: 62,052
  • Joined: 12-June 08

Re: Creating a video game using windows.h windows api

Posted 05 September 2019 - 08:54 AM

Curious side question - why Windows 32 API?
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Creating a video game using windows.h windows api

Posted 05 September 2019 - 06:58 PM

View PostThunderer, on 05 September 2019 - 11:47 AM, said:

How to know how much time elapsed since the program started?

Most Windows programs just depend to GetTickCount(). They may note of what the current tick count is when the program starts, and then compute the delta from there. Others just get the current machine time and compute the delta. There are high resolution performance counters if you need more precision. There are also other API that let you query Windows process state to determine how much CPU time has been used by a process.
Was This Post Helpful? 2
  • +
  • -

#6 Thunderer   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 132
  • Joined: 25-June 17

Re: Creating a video game using windows.h windows api

Posted 05 September 2019 - 08:26 PM

What is the use of graphic card, what calculation does it do and how does it make the game faster? How to play sound in windows API?

This post has been edited by Thunderer: 05 September 2019 - 11:04 PM

Was This Post Helpful? 0
  • +
  • -

#7 Radius Nightly   User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 321
  • Joined: 07-May 15

Re: Creating a video game using windows.h windows api

Posted 06 September 2019 - 10:50 AM

With that idea, you can make games, but 2D, and since most of the things has to be calculated by CPU, dont expect some miracle, GPU probably wont be used at all, and you will still be able to make fine games (but over time it may become too complex), specialy for time counts, because there are multiple variants of how computer can calculate time, and none of them are actually perfect. So if you wanna make games, use the right tool for the right job.
Was This Post Helpful? 0
  • +
  • -

#8 NicVene   User is offline

  • New D.I.C Head

Reputation: 10
  • View blog
  • Posts: 9
  • Joined: 28-May 19

Re: Creating a video game using windows.h windows api

Posted 09 September 2019 - 03:50 PM

View PostThunderer, on 05 September 2019 - 08:26 PM, said:

What is the use of graphic card, what calculation does it do and how does it make the game faster?


This is a substantial topic, but I'll try to be to the point.

A modern GPU process both 3D model data and 2D image data very rapidly using specialized hardware. Even in 2D gaming, the same features in the GPU present rapid frame display using specialized techniques.

A great deal depends on the artwork itself, so relative performance is impossible to state clearly, but typically one might witness barely 1 frame per second if the CPU performs all of the work, where that same graphic material and quality may be rendered by the GPU well over 60 frames per second. Depending on the GPU in question, that could go as far as several hundred frames per second.

There are typical operations performed in gaming. For 3D models this involves linear algebra, which mathematically models a 'camera' (or player's eye view) of a scene. These operations are particularly taxing on CPU resources, where the GPU is designed specifically for that math.

Where typical CPU's may have 4 to 16 cores, GPU's may offer hundreds or thousands working in parallel. This is the primary means by which they generate high performance.

The CPU itself, however, has certain beneficial traits which suit it for generalized software. The GPU is particularly bad at branching, which is to say it's bad at making simple decisions they way a general CPU does. The GPU is tuned to work on lists of tens of thousands of points (usually 3D points, but could be 2D points) without stopping - which is typically how graphics data is processed.

There is a second phase in the GPU (one might say several, but at least 2). Once the 3D models have been transformed according to the camera view, they must be textured. This process is programmable in modern GPU's, and is responsible for a number of special effects. The basic idea is to take the image of a texture, like a brick wall, and paint that onto a shape (like a rectangular solid) to make that shape look like a brick wall. Obviously, there are multiple textures and therefore multiple sources, but this process is basically operated pixel by pixel. Doing that in the CPU would be very slow. The GPU has specialized processing units built just for this phase of the process, and includes programmable processors (called shaders) to perform the work in highly parallel fashion.

The result is many orders of magnitude in performance.

The GPU can also be tasked with computation of high volume that never displays anything, often used for physics, special effects or other applications like video processing, encryption/decryption and artificial intelligence.

GPU's don't just make games faster, they can make nearly all large volume calculations faster.
Was This Post Helpful? 1
  • +
  • -

#9 Thunderer   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 132
  • Joined: 25-June 17

Re: Creating a video game using windows.h windows api

Posted 14 January 2020 - 12:46 AM

The thing is I want to create a rendering pipeline by hand and I nearly developed the plan and the math (I want to practice math and coding). I can make my code run in cpu (simply compile it in GCC). How can I use GPU acceleration (opencl or something?) . Easier is better, if not I want to find tutorials :)/> ... I want my program to be light weight .

This post has been edited by Thunderer: 14 January 2020 - 01:25 AM

Was This Post Helpful? 0
  • +
  • -

#10 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Creating a video game using windows.h windows api

Posted 14 January 2020 - 05:04 AM

View PostThunderer, on 14 January 2020 - 02:46 AM, said:

I can make my code run in cpu (simply compile it in GCC). How can I use GPU acceleration (opencl or something?) .

These two are at odds with each other. You can have it run in CPU, or you can have it run in GPU. There is no currently no magic library that lets you compile once for CPU, and then the GPU will just magically take the x86/x64 assembly and make it run in on the GPU. There maybe some GPU acceleration happening for you, but that will be happening at the Windows driver level, not in your user mode application level.
Was This Post Helpful? 0
  • +
  • -

#11 Ornstein   User is offline

  • D.I.C Head

Reputation: 32
  • View blog
  • Posts: 64
  • Joined: 13-May 15

Re: Creating a video game using windows.h windows api

Posted 14 January 2020 - 05:45 AM

People do write 100% CPU software renderers (usually for fun or educational purposes), but you'll struggle to get them to satisfy certain performance requirements on typical hardware.

If you just want some experimental experience with the maths and such, you could potentially go down the OpenCL route (or similar) as you suggested - or you could just implement as much as possible (which should be pretty much everything these days) in a shader.
Was This Post Helpful? 0
  • +
  • -

#12 Thunderer   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 132
  • Joined: 25-June 17

Re: Creating a video game using windows.h windows api

Posted 14 January 2020 - 06:32 AM

I decided full CPU code. My goal is simplicity. I want small size compliers and small size executables. When my friends wanted to make games I told them about directx they were confused. I will make a simple rendering pipeline and a tool for making game helpful for making simple games. I always wanted such a tool. In india download size is a big headache. Can GPU still help me?
Was This Post Helpful? 0
  • +
  • -

#13 Thunderer   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 132
  • Joined: 25-June 17

Re: Creating a video game using windows.h windows api

Posted 14 January 2020 - 06:40 AM

What do you mean? In opencl, the kernel code is run in gpu and the other one (normal code) in cpu. Isn't it? I am bad in english, it is not what I speak in home.

This post has been edited by Skydiver: 14 January 2020 - 10:20 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#14 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Creating a video game using windows.h windows api

Posted 14 January 2020 - 10:19 AM

The "kernel" in OpenCL you are referring to there is the shader code that runs on the GPU. It is not the same as the "kernel" referring to the OS that runs on the CPU. Code that runs on the GPU needs to be compiled for that GPU. Those compiled bits for the GPU will not run on a regular x86/x64 processor. Conversely, code compiled for a x86/x64 processor will not run natively on a GPU.
Was This Post Helpful? 0
  • +
  • -

#15 Thunderer   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 132
  • Joined: 25-June 17

Re: Creating a video game using windows.h windows api

Posted 28 January 2020 - 05:33 AM

I am afraid to start two thread (correct me if it is against the rules). To create a game like BC Kings (search on steam) should I do by on cpu rendering or direct x (I am already learning). Learning curve is a big bad for me. (I am not much experienced on games, so share your experience.) Time is not bad for me, the project may take years :). I am telling learning curve is bad for me because in India no one make games (no such companies) so the knowledge will be useless better I create a complex and big project...
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2