http://asawicki.info/ Programming, graphics, games, media, C++, Windows, Internet and more...
All blog entries, ordered from most recent. Entry count: 1041.
I just came back from Revision - world's biggest pure demoscene party. It was held in Saarbrücken, Germany. That was first time I attended a demoparty abroad, as I've been going only to the ones in Poland so far, like RiverWash, WeCan, Silly Venture, or AmiWaWa.
I don't like the fact that it happens during Easter, when I usually go visit my parents, but I wanted to see it at least once. Revision was big, with around 700 participants, according to the page with non-mandatory registration - Visitors. There were various kinds of activities - from Seminars to techno party, and of course most importantly - competitions. Revision is a multiplatform demoparty, so there were compo categories dedicated to retro platforms (like Amiga, pixel art or tracker music), as well as modern PCs (like modern graphics, streaming music, PC 4K/8K/64K intro and demo). Entries can be found here: Revision 2017 @ pouet.net.
Many people said that PC 4K Intro category had best quality this year, so it's worth checking. Other than that, productions that I remembered the most are:
Most exciting for me was watching Shader Showdown - a competition where two programmers had to write a pixel shader live on stage, without any documentation or other help, in a time frame of 25 minutes per round. Winner moved on to semifinals and then the final. During each round a DJ was playing some music and its live FFT was available as one of the inputs to the shader. It's amazing to see how good knowledge of programming, graphics and math allows to develop some nice looking visualizations in such a short period of time. I've also heard opinions that watching it gave a good glimpse of how graphics programming looks like and what does it take to make a demo, even for non-technical people.
Here is a gallery of my photos from the event:
EditorConfig to the Rescue for Multiple Projects
I was once asked to participate in a project where coding standard required to use indentation of 3 spaces - different than what I do normally, when I use 4 spaces. I was searching Internet for answer whether Visual Studio supports per-project settings for this and I've found out that it doesn't, but came across this instead: EditorConfig.
This technology is so simple you can learn all about it in just few minutes, still very useful for cases like mine. You can basically create text file called
.editorconfig in root directory of your project and describe configuration for editors using a simple language. For example:
root = true
charset = utf-8
indent_style = space
indent_size = 3
Of course your text editor must support that. It turns out many of them support this standard natively. Editors I care about have plugins for that available. Unfortunately the one for jEdit doesn't seem to work (I've reported this issue), but the one for Visual Studio works perfectly. Now I could have per-project configuration for text editor, including character set, line ending type, and indentation type (tabs versus spaces and the number of spaces).
There are Too Many Messaging Apps
I can remember time when Internet was still young and the basic mean of communication was e-mail. Real-time chat was possible through IRC protocol. Later, changes came with the appearance of Instant Messaging (IM) apps, from which ICQ was probably the first. There were many of them, all having similar, basic functionality - list of contacts, seeing their status (available, away, offline) and chat. Gadu-Gadu (renamed later to GG) was local one very popular in Poland, but others were also in use, like AOL, MSN, Jabber.
Over time clients for those networks became bloated with more or less useful features, fancy skins and emoticons, and of course lots of ads - which all consumed additional RAM and CPU time, not to mention just being annoying. Then, something wonderful happened - alternative clients started to appear. Whether based on open protocols (like Jabber) or reverse-engineering others, these multi-communicators were often lightweight, supported alternative platforms (like Pidgin working on Linux) and integrated support for many protocols in a single app, with single list of contacts and unified user interface. My favorite one was Konnekt and later AQQ.
New era started probably with Skype, which for most of us was an introduction to new features like audio- and videochat. Next generation communication apps became more complex, provide more useful features, but at the same time they are even more resource-heavy and (in case of smartphones) drain battery. For some reasons they have no alternative clients (probably because their protocols are more complex, proprietary, and encrypted). And there are many of them. So here I am today, having multiple messaging apps installed on my smartphone. I do most of chatting with my friends via Facebook Messenger these days, but some of them prefer other program, so I ocasionally use also: Skype, Telegram, WhatsApp, Signal, Slack, Google Talk and Hangouts, plus of course the old good phone calls, SMS, and e-mail. What a mess!
At the same time I can see they all start to converge. They look similar as it becomes more and more clear what's the optimal user interface for such app. Features added to some of them quickly appear in others, like end-to-end encryption or (most recently) commenting others' messages with a smiley. So I think the future is once again to have a single messaging app. I only hope it will be just a GUI supporting multiple protocols, and not one of those "Big Brother" corporations (who already know everything about as) dominating all the messaging, just like Gmail dominated market of e-mail servers and readers.
Vulkan Bits and Pieces: Writing to an Attachment
One of the reasons why new generation graphics APIs (DirectX 12 and Vulkan) are so complicated, is that they have so many levels of indirection in referring to anything. For example, when you render pixels to a color attachment (also known as “render target” in other APIs), the path is as follows:
outColor = vec4(1.0, 0.0, 0.0, 1.0);
layout(location = 0) out vec4 outColor;
VkSubpassDescription::pColorAttachments- member of the structure that describes rendering subpass.
VkAttachmentReference::attachmentprovides another INDEX, this time to an array pointed by
VkRenderPassCreateInfo::pAttachments- member of the structure that describes rendering pass.
VkAttachmentDescriptionprovide just few parameters, like format.
VkFramebufferCreateInfo::pAttachments- member of a structure filled when creating a framebuffer that is going to be pointed by
VkRenderPassBeginInfo::framebufferwhen starting actual execution of the render pass.
VkImageView, so each of them is a VIEW to an image, pointed by
VkImageViewCreateInfo::image- member of a structure used when creating the view.
VkImage) is either obtained from swap chain using function
vkGetSwapchainImagesKHR, or created manually using function
VkDeviceMemory) with function
vkAllocateMemoryand bind its fragment to the image using function
vkBindImageMemory. This is the memory that will be actually written.
Yeah, Vuklan is hard…
Microsoft Visual Studio 2017 - My Experience
Visual Studio 2017 came out recently. The list of news looks like it has been written by some marketing rather than technial guys. It starts with "Unparalleled productivity for any dev, any app, and any platform. Use Visual Studio 2017 to develop apps for Android, iOS, Windows, Linux, web, and cloud. Code fast, debug and diagnose with ease, test often, and release with confidence. You can also extend and customize Visual Studio by building your own extensions. Use version control, be agile, and collaborate efficiently with this new release!" - I've never seen so many buzzwords in just one paragraph.
Rest of the page is not different. They even call their installer "a new setup experience". They've also introduced "Lightweight Solution load", which is disabled by default - like everyone is assumed to prefer slower option :) Some other changes: "Visual Studio starts faster, is more responsive, and uses less memory than before." - that's unexpected direction. "Performance improvement: basic_string::operator== now checks the string's size before comparing the strings' contents." - wow, that's genius! They should file a patent for that ;) I hope they do the same for std::vector and other STL containers.
OK, but jokes aside, I've installed it on my personal PC, it installed quite fast and it works good. It preserved my settings, like the list of Include and Library Directories. Upgrade of my home projects went smoothly, without any problems.
There are many changes valuable for native code developers. What's New for Visual C++ in Visual Studio 2017 page mentions over 250 bug fixes, other compiler improvements and improved support for C++11, 14, and 17. I've already heard stories of programs running much faster after recompilation with this new compiler.
Contrary to what I thought before, Microsoft didn't abandon Graphics Diagnostics embedded into MSVS after they released new standalone PIX. They've actually added some new features to it.
So I definitely recommend upgrading to Visual Studio 2017. It is IMHO the best C++ IDE, and the new version is just next step in the right direction.
It seems that there is no new version of "Microsoft Visual C++ Redistributable Package" this time. Programs compiled with VS 2017 use VCRUNTIME140.DLL, just like in 2015 version.
How to change display mode using WinAPI?
If you write a graphics application or a game, you may want to make it fullscreen and set specific screen resolution. In DirectX there are functions for that, but if you use OpenGL or Vulkan, you need another way to accomplish that. I've researched the topic recently and I've found that Windows API supports enumerating display devices and modes with functions:
EnumDisplaySettings, as well as changing mode with function
ChangeDisplaySettingsEx. It's a programatic access to more or less the same set of features that you can access manually by going to "Display settings" system window.
I've prepared an example C program demonstrating how to use these functions:
First you may want to enumerate available Adapters. To do this, call function
EnumDisplayDevices multiple times. Pass
NULL as first parameter (
LPCWSTR lpDevice). As the second parameter pass subsequent
DWORD Adapter index, starting from 0. Enumeration should continue as long as the function returns
BOOL nonzero. When it returns zero, it means there are no more Adapters and that Adapter with given index and any higher index could not be retrieved.
For each successfully retrieved Adapter,
DISPLAY_DEVICE structure is filled by the function. It contains following members:
WCHAR DeviceName- string with name of the Adapter, like "\\.\DISPLAY1".
WCHAR DeviceString- string with more user-friendly name of the Adapter, like "AMD Radeon (TM) RX 480".
DWORD StateFlags- various flags, like
DISPLAY_DEVICE_ACTIVEif the device is on, or
DISPLAY_DEVICE_PRIMARY_DEVICEif this is the primary device.
There is a second level: Adapters contain Display Devices. To enumerate them, use the same function
EnumDisplayDevices, but this time pass Adapter
DeviceName as first parameter. This way you will enumerate Display Devices inside that Adapter, described by the same structure
DISPLAY_DEVICE. For example, my system returns
DeviceName = "\\.\DISPLAY1\Monitor0",
DeviceString = "Generic PnP Monitor".
The meaning and the difference between "Adapter" and "Display Device" is not fully clear to me. You may think that Adapter is a single GPU (graphics card), but it turns out not to be the case. I have a single graphics card and yet my system reports 6 Adapters, each having 0 or 1 Display Device. That can mean Adapter is more like a single monitor output (e.g. HDMI, DisplayPort, VGA) on the graphics card. This seems true unless you have two monitors running in "Duplicate" mode - then two Display Devices are reported inside one Adapter.
Then there is a list of supported Display Settings (or Modes). You can enumerate them in similar fashion using
EnumDisplaySettings function, which fills
DEVMODE structure. It seems that Modes belong to an Adapter, not a Display Device, so as first parameter to this function you must to pass
DISPLAY_DEVICE::DeviceName returned by
EnumDisplayDevices(NULL, ...), not
EnumDisplaySettings(adapter.DeviceName, ...). The structure is quite complex, but the function fills only following members:
DWORD dmPelsWidth, dmPelsHeight- resolution, in pixels.
DWORD dmBitsPerPel- bits per pixel (all Modes have 32 in my case).
DWORD dmDisplayFrequency- refresh rate, in Hz.
DWORD dmDisplayFlags- additional flags, like
DM_INTERLACEDfor interlaced mode.
I have a single graphics card (AMD Radeon RX 480) with two Full HD (1920 x 1080) monitors connected. You can see example output of the program from my system here: ExampleOutput.txt.
To change display mode, use function
LPCTSTR lpszDeviceName), pass
DeviceNameof the chosen Adapter (again, not Display Device!).
DEVMODE *lpDevMode), pass structure filled with desired Display Settings. You can fill it by yourself, but Microsoft recommends to pass the copy of the structure as it was retrieved from function
DWORD dwFlags), you can pass various flags, e.g. whether new settings should be saved in the registry.
The function returns
DISP_CHANGE_SUCCESSFUL if display mode was successfully changed and one of other
DISP_CHANGE_* constants if it failed.
To restore original display mode, call the function like this:
ChangeDisplaySettingsEx(targetDeviceName, NULL, NULL, 0, NULL);
Unfortunately, display mode changed in the way described here is not automatically restored after user switches to some other application (e.g. using Alt+Tab), like in DirectX fullscreen mode, but you can handle it yourself. Good news is that if you pass
CDS_FULLSCREEN flag to
ChangeDisplaySettingsEx, the previous mode is automatically restored by the system when your application exits or crashes.
First Time on GDC
I came back from my first GDC. I've been dreaming about going there since my university years. My first impression? It's huge! It runs for so many days (Monday to Friday). There are so many talks, more than a dozen at same time, that you really need to choose carefully what is most interesting to you (and stand in a queue before the room, because if you come too late and the talk is very popular, there may be no free seats left).
As the world's largest event of this kind in the industry, it attracts best professionals and offers quality talks. This time there were sponsored talks from Amazon (about their engine Lumberyard), Facebook, Khronos, Google, NVIDIA, Unity, Intel, Microsoft, Oculus, AMD, Epic, ARM, Sony and others - basically every big company that deals with graphics, plus many other talks presented by individual developers. I was interested mostly in graphics programming, but of course there were many other topics covered, like artistic or business aspect of game development.
Expo was also big, with over 100 companies presenting their products, services and technologies. Big difference from Polish Pozna˝ Game Arena is that GDC is targeted to professionals only, which means there aren't such big crowds of people standing in long queues to be able to play any game. I've never played so much VR as on this expo :)
There were other attractions too, like indie game developers presenting their productions or retro zone with working computers from previous decades. So many things to do there! In addition to that, I've met many friends there, who either live in US or came from Poland just like me.
Entrance fee is high, with pass for main conference starting at $1000 up to $2400 (on-site for all access), aside from plane ticket to San Franscisco and hotel there, so it's hard to go there on your own, unless your company pays for it. But if only you have the opportunity, I think GDC is definitely worth visiting.
By the way, gamedev conferences planned for this year in Poland are:
I hope to visit them all :)
Gallery of my photos (mostly from San Francisco):
How to download videos from YouTube and other sites in Full HD (1080p)?
If you, just like me, don't like to rely on data stored in the "cloud" (i.e. someone else's computer) and prefer to have it available offline on your hard drive, you probably tried to find a way to download video and music from YouTube and other similar services. There are web pages for that, but they are full of ads, malware and fake "Download" buttons. That's why my favorite way is to use youtube-dl. It works perfectly, is constantly updated and maintained, is open source and supports downloading from almost 1000 (!) different websites, including YouTube, Vimeo, Facebook videos, Soundcloud, Mixcloud and even XXX websites. The only drawback: it's a command line program, so you have to download it and then run it from console with correct parameters. But it's actually quite simple, as you can see below.
To use it, first go to the youtube-dl website and download "Windows executable". It's a single file -
youtube-dl.exe, which doesn't need any installation. Just put it in some directory on your hard disk, like I did in
Next, browse to YouTube or other website, find the video you want to download and copy its URL (link) from address bar to the clipboard. Example: "https://www.youtube.com/watch?v=9bZkp7q19f0".
Finally, open command prompt. In Windows 10 you can do it e.g. by opening Start menu and searching for "Command Prompt". In the console, issue following commands:
F:- to change drive to correct one, if needed.
cd \Programs- to enter the directory with your program.
youtube-dl.exe https://www.youtube.com/watch?v=9bZkp7q19f0- to download video from specific URL.
The video is downloaded to the same directory where you've put the program. Its file name contains title of the video, its YouTube identifier and correct extension, depending on particular video format. For example, mine was: "PSY - GANGNAM STYLE() M_V-9bZkp7q19f0.mp4".
That's all basically, but please keep reading if you want to avoid unpleasant suprises, because there are still two important things to know.
First is that sometimes downloading doesn't work. It happens probably because YouTube changes the way the video is served on their website, like the details of their HTML code. Fortunately youtube-dl is quickly adjusted to it, so if you encounter any download error, you probably just need to update the program to the latest version. You don't even need to go to their website - the program has a feature to update itself. All you need to do is to issue command:
Second problem is that youtube-dl only downloads YouTube videos in HD (720p) quality, not Full HD (1080p). That's because YouTube provides Full HD video and audio streams separately so they need to be merged on the client side. Good news is that youtube-dl can do it for you. Bad news: it needs additional program for that, called FFmpeg. So to be able to download videos in FullHD quality, you should additionally:
F:\Programs. This software also doesn't need any installation.
binsubdirectory, where you can find
ffmpeg.exeand save its path. In my case it is:
Now, to download Full HD video, issue following console commands:
F:- to change drive to correct one, if needed.
cd \Programs- to enter the directory with youtube-dl.
set PATH=%PATH%;f:\Programs\ffmpeg-20170214-8fa18e0-win64-static\bin- to temporarily add directory with
PATHenvironmental variable, so youtube-dl will be able to use it.
youtube-dl.exe -f bestvideo+bestaudio https://www.youtube.com/watch?v=9bZkp7q19f0- to download video from specific URL using best video and audio quality available.
Now youtube-dl will download the video stream, audio stream and merge them into final file using FFmpeg, so you can enjoy best quality video and audio, downloaded on your hard drive.