Posts

C++ Console : Advance Graphic Techniques

Image
     When i started programming first time i started with C++. Despite people say it's hard or too basic or whatever, i personally can confirm that using C++ a programmer can build very strong skills of logic building as well as core concept of programming. We can understand errors, working and advanced concepts of computer (data structures, data bases, data security, hacking) easily.      For beginners projects like little games are very interesting and full of knowledge. I made my first project with simple graphics because i was not able to find complex codes and understand them to use for myself. Similar case is with existing libraries like Graphics.h, OpenGL etc. They are too complex for beginners. So i have compiled a library for beginners with some basic fuunctions that you guys can use to print anything on console at pixel level. Here is a comperison of my project with simple graphics and a simple combination of shapes with my new graphics library:...

C++ Console : Sound Play

Console is not as boring as it looks right? So far we have seen that there is nothing that is not possible with console. Here we have yet another good thing that can be very interesting for console programmers and is very good for gaming projects. Sound play in console is not very difficult. If code is arranged in specific manner then it's just to use the code and have fun. Please read these notes first: link must have \\ between two folder names like "D:\\ folder 1 \\ folder 2 \\ folder 3 \\ file.wav " write filename correctly with it's extension .wav audio files other then .wav are not supported by this convert your files to .wav via convertor or online site like this:  Convert Audio Online Let's have a look at code: #include <Windows.h> #pragma comment (lib,"winmm.lib") void soundPlay(LPCWSTR link); void soundStop(); UINT wDeviceID; void main(){ LPCWSTR link = TEXT("D:\\tone.wav"); soundPlay(link); ...

C++ Console : Basic Graphic Techniques

Image
     Console is basically a text panel and this being the reason it is slow for rendering (printing) on it. There are again 2 ways to print on console. Pixel by pixel which is used for printing images and anything is possible with that but this method will yield slow printing speed and that is not very helpful in games or usual applications but in rare cases it may be helpful like making little bit of logos and graphs.      The 2nd method is to use predefined ASCII characters to make a whole shape. This is fast method but since characters are fairly bigger than single pixel (about 1:10 - +) ratio so they are not helpful in making curve shapes. Here is a link   and code to get ASCII table characters view and select which one you might like to use: #include <iostream> using namespace std; void main( ){ cout<<"value\tcharacter"<<endl; for ( int i = 0; i <= 255; i++){ cout<<i<<"\t"<<ch...

C++ Console : Keyboard Input for Games

Usually we need arrow keys input for simple games like luddo, tic-tac-toe or any board game. Here is a simplified code for getting input from arrow keys of keyboard. As you read code you can easily edit it for your own choice buttons and return values of the input function. #include <iostream> #include <windows.h> #include <conio.h> using namespace std; int getArrowKeyInput(); void main(){ char user = getArrowKeyInput(); while (user != 'e'){ cout << user << endl; user = getArrowKeyInput(); } system("pause"); } int getArrowKeyInput(){ int input = _getch(); char return_value; if (GetAsyncKeyState(VK_DOWN)){ _getch(); return_value = 'd'; } else if (GetAsyncKeyState(VK_RIGHT)){ _getch(); return_value = 'r'; } else if (GetAs...

Diamond and other Shapes in Console : Make them hollow

Image
     To get the idea of printing a shape in c++ console, read this article . Here we'll discuss how will we implement hollowness in the shapes that we made in previous article.      First revise the code of square, easy wasn't it? So is to implement hollowness in it. We just need some if statements to bypass the process of filling the shape. OK, have a look in nested loop of square code: #include <iostream> using namespace std; void main(){ int width = 8, height = 5; char custom_character = '*'; for (int i = 0; i < height; i++) { for (int i = 0; i < width; i++) { cout << custom_character; } cout << endl; } system("pause"); }      What we need to do here is that when this loop starts, it should print 1 character and then for rest n-2 character it should print some character which will have no shape like SPACE. It'll show hollowness in shape and similarl...

C++ Console : Change Font Size

Image
Font size is not a very big deal but i had to post it's code here because we'll be using it to change the fonts of our console in such ratio that will help us making geometric shapes like squares, easily and perfectly. Here is a list of available ratios that a console supports. You can use either of them: 4:6 6:8 8:8 16:8 5:12 7:12 16:12 12:16 10:18 Code: #include <iostream> #include <Windows.h> using namespace std; HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); void fontsize(int,int); void main(){ fontsize(8, 8); cout << "This is a symmetrical font" << endl; system("pause"); } void fontsize(int a, int b){ PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx = new CONSOLE_FONT_INFOEX(); lpConsoleCurrentFontEx->cbSize = sizeof(CONSOLE_FONT_INFOEX); GetCurrentConsoleFontEx(out, 0, lpConsoleCurrentFontEx); lpConsoleCurrentFontEx->dwFontSize.X = a; lpConsoleCurrentFontEx-...

C++ Console : Full Screen

Image
     As soon as i grasped on programming, i felt like it was too boring to run programs in console where black and white and small screen is strictly applied on my head and i have to just go with it. But software is not a name of limit or stopping. It is meant to create anything which is not even possible in real world. So today i'm sharing with you a simple code which you can save and use in various C++ projects you can also visit this post where you can see how console is colored so that you can achieve some basic level of satisfaction. #include <iostream> #include <Windows.h> using namespace std; HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); void fullscreen(); void main(){ fullscreen(); cout << "Console is now in full screen size" << endl; system("pause"); } void fullscreen(){ COORD NewSBSize = GetLargestConsoleWindowSize(out); NewSBSize.Y += 3; NewSBSize.X -= 2; SMALL_RECT DisplayA...