2

I was making some games using Game Maker, but I would like to make simple games using C. I am a newb C programmer. When I code the output is always in the CMD Windows Console. I could make some simple games but always in the console, which is not very flexible (you can't animate without scrolling). When you run a more complex game, a complete new screen is created and I actually interact whit that screen.

So the question that i am having using C language is: How is this new screen being loaded? I think there is some windows API to create a new screen or something. By the way, in the old times, I mean DOS time, you just used a console but you could load a new screen where the game was played. How can you achieve this?

I would like some guideline to research the root. I just don't want to call library X or use SDL.

Thanks your your help.

Kostadin
  • 405
  • 3
  • 14
Carlitos_30
  • 371
  • 4
  • 13
  • Welcome to SO! Your question is very broad and somewhat opinion-based. On SO, you should try to ask objective questions that generally consist of code examples, asking specific questions. – Joseph Boyle Feb 14 '14 at 15:54
  • Though I'm all for beginning programmers being enthusiastic, and taking on projects that are stretching their capabilities, there is a line. You say you're new to C. Consider learning the basics of the language: Create a parser, that structures the consumed text in a linked list. That's a challenging project for a beginner. Once you've mastered the basics of scopes, memory management and pointer arithmetic, _then_ you can learn to write GUI applications using one of many API's. Sorry, to say this: don't run before you can crawl, and certainly don't try to compete in the Olympics – Elias Van Ootegem Feb 14 '14 at 16:24
  • @Elias Van Ootegem `That is very bad advice considering you completely missed what he was asking. If he can make a fully functioning game in a console, he is plenty familiar with C to start making simple graphical windows for his games. They don't have to be super complex or sophisticated. They can be very simple. He is asking how to create new windows in the windows stack and draw his game GFX there. Don't shun the guy for reaching beyond what you wouldn't due to fear of lack of skill. As a coder/programmer (if you are one) you know the best way to learn is to do. Don't give bad advice.` – Yokai Nov 13 '17 at 09:46
  • @Yokai: I was basing my advice on this piece from the OP's question: _" I am a newb C programmer"_. I am a developer, and I've felt the frustration and disappointment of biting of more than you can chew plenty of times. If you want to encourage people to stick with it, I think encouraging them to start with the basics, and working their way up is the way to go. Left this as a comment as this is mainly one persons opinion, not a golden rule. My intentions were not to shun or scoff at all. My intentions were to spare someone the frustration of starting a project and perhaps not finishing it... – Elias Van Ootegem Nov 13 '17 at 10:22
  • While I can understand your reply, I have been bashing the shell and programming in C for over 6 years and consider myself still new to it. It is, I believe, more of a humility statement rather than literally being new to C. Especially if, like I mentioned, he can make full console games already (obviously this depends on the complexity of the games in question). I am just giving an alternate point of view by reading his question in a different possible context. – Yokai Nov 14 '17 at 08:29

3 Answers3

1

Since you mention library X i assume you are on a Linux system. There are several different ways to archive your goal. If you would like to still use the console but with more graphics involved you could take a look at library ncurses ( http://www.gnu.org/software/ncurses/ ).

If you want to do more advanced graphics i recommend you to take a look here : How do you create a window in Linux with C++?

Community
  • 1
  • 1
MrSykkox
  • 528
  • 4
  • 14
  • When I wrote library X, I meant a generic library, like library foo. It is always necesary to use a library? I think the library hiddes the complicates stuff I would like to learn. – Carlitos_30 Feb 14 '14 at 16:17
  • So your are asking for a API for Windows or for console? If looking for window api, Michael has answered your question. – MrSykkox Feb 14 '14 at 16:25
1

Creating new Windows can get pretty hairy (ie. the code can be complicated and difficult to read). I'll try to give a somewhat high-level overview, then link you to a good tutorial for loading a basic window.

You need to declare a couple of variables of types HWND and WNDCLASSEX, and call a bunch of Windows API functions to initialize the Window with some settings and whatnot.

Once this is done, you need to enter a loop that handles all the window interactions, usually with TranslateMessage and DispatchMessage inside the loop.

You also need to implement a callback procedure for handling Windows events such as mouse clicks, closing the window, etc. This is usually done in a LRESULT CALLBACK WndProcedure.

I've now thrown a bunch of new words and ideas around with little explanation; check out this tutorial for a full example of what I've just tried to explain.

http://www.functionx.com/win32/Lesson01c.htm

(EDIT: the link above is dead now, so here's a link to a cache of it from the Wayback Machine https://web.archive.org/web/20190203182520/http://www.functionx.com/win32/Lesson01c.htm)

Hope this helps!

Also - this is all assuming you're on Windows based on your comment about a Windows API (ie. windows.h). If you're on Linux, you'll need to use X.

Michael Oliver
  • 1,392
  • 8
  • 22
  • But in the 80's, with DOS, you could make a new screen for the game.The OS gave some API too?. – Carlitos_30 Feb 14 '14 at 16:14
  • I wasn't around for DOS, but I assume that yes, there was an API needed. I think what you're trying to do is create a window without using any API and just C. This can't be done; you need to write a lot of assembly since you're dealing with GPU hardware. Also, accessing the GPU in this way isn't easy as generally they aren't open source. Programming assembly without the specifications is incredibly hard, and very few people can do it. I wouldn't recommend trying. Windows gets its name for a reason by providing an API for creating windows/GUIs. It's meant to be used for this exact purpose. – Michael Oliver Feb 14 '14 at 23:53
  • The link in your answer is dead now, but I'd just like to recommend the first few episodes of Handmade Hero on YouTube as a great resource for learning how to integrate with the WinAPI. – el toro Dec 08 '19 at 14:45
  • Thanks for pointing that out @eltoro, I've added a link to a cached version of that site. – Michael Oliver Feb 24 '20 at 19:01
1

C programming dates back to 1970's, so you can think of creating games similar to that era. The window or the new screen is loaded by few preprocessor directives which are already compiled and stored by the developers. A new screen can be achieved by giving a few commands:

  #include<stdio.h>
  #include<conio.h>
  void main()
  {

  local declarations;
  And your program for the game;

  getch();
}

What this basically do is the function getch(); which is stored in (conio.h) will open a new window and it will display the output till it gets a value from the keyboard ie it displays the output till you press any key from the keyboard.

hope this answer helps you.

Chetan
  • 11
  • 2