Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 26 Mar 2013
Online Last Active Today, 02:20 PM

#5314284 How to make console-like GUI

Posted by on 07 October 2016 - 01:44 PM

Hey Joylio,


The example your referencing is most likely a Render to Texture technique. (Notice the fish eye-lens effect of the display to simulate a bulged CRT monitor. It's most likely accomplished by what's known as a Shader.) Now if you mean like a Command prompt in a GUI, there is a way to "fake" it. Insofar as actually embedding a command prompt within a Window, i'm not sure if that's possible.


Basically you would make a sub-window, make it look like a console window, and then you would redirect console commands to this sub-window. (incidentally I did something like this in Java recently with Swing) There is documentation for this for Win32. But, you use QT so another member may be a bit more help there.


Here's a MSDN article for retrieving, and redirecting a handle to stdIn, out, and error. Take a gander, and don't let the ugly code sway you either way since this is for Win32, not QT. But, I can't imagine the overall flow would be terribly different (of course i've never used QT so who knows)





#5303735 Prevent Reassignment Of Handle

Posted by on 02 August 2016 - 07:54 PM

Well one thought comes to mind. In C/C++ you can define an objects assignment operator to be private. In angel script the syntax I pulled from their docs looks something like this:

obj@ opAssign(const obj &in other)
    // Do the proper assignment
    // Return a handle to self, so that multiple assignments can be chained
    return this;

So you could try something like this: (Treat this as psuedocode as I am not sure if the syntax is correct)

class myObj
    private myObj opAssign(const obj &in other) { return this; } 

I'm guessing for the most part here as to the functionality of the code I have just given you. Since I've never written a line of AngelScript ever before :P

I'm viewing this from a C++ perspective, but according to the docs, and what it seems your asking for is well within the scope of the language.


In case my explanation is not par, take a gander from where I sourced it.





Marcus Hansen

#5300612 Starting my new game JS HTML

Posted by on 13 July 2016 - 04:42 PM

It's a start.


Insofar as your language choice, c/c++ isn't a prerequisite for game development at all, so don't feel pressured to learn something you don't feel your ready to undertake. Javascript is an excellent choice for browser based games, and to my knowledge that most used one for interfacing with Browser Based 3D API's such as WebGL.


Also no matter what language you choose usually the same schematics are employed for a Games underlying structure. That is, the game loop. The game loop is a conditional loop that performs all of the games necessary functions until a condition is met that ends the application lifecycle.


Kinda like this:

While (GameState != APP_CLOSE) do

Marcus Hansen

#5298124 Basic texturing

Posted by on 26 June 2016 - 11:52 AM

Very much depends on your use scenario. Does the texel being evaluated through your pixel shader only reference a single texture for it's computation? If your making a game that only needs simple texturing, and to have it sampled by a single SamplerState at any given shader execution, sure one Texture2D, and SamplerState should be fine.


As MJP stated, you'll change the texture, and sampler bindslots cpu side for different textures, and (if need be) corresponding samplers, and the bindslots will retain there textures, and samplers between draw calls, and shader swaps. 


The website you mentioned will eventually step you through more advanced use scenarios where for a given texel you'll evaluate it against several textures, such as, normal maps, shadow maps, and ect.


Marcus Hansen

#5297356 what means these error?

Posted by on 20 June 2016 - 02:12 PM

Hello Cambalinho,


it has been awhile since I received a similar error, so I had to do a little bit of research. The general consensus is that the error is given when attempting to access a pointer that has either not been properly initialized, or has been deleted. Essentially trying to de-reference a dangling pointer that may point to an unexpected area in memory. If my explanation proves to be insufficient, i'll attempt to clarify, or through a google search you will be able to procure a wealth of info in regards to this particular error.


Might also be helpful to post the source file(s) that is generating the errors.


Marcus Hansen

#5296649 How to avoid Singletons/global variables

Posted by on 15 June 2016 - 08:27 AM

I always love practical examples.


void SomeFunc() //This function requires no argument. So it appears to be relatively standalone


    mySingletonClass* mySingletonClass::getSingletonObject() //Oh, you evil sob

    //does something




If the project is small as others have stated, AND you, and/or one other guy are they only developers touching the code. A singleton could be justified. But take a look at that function. How am I, as a curious passerby in the project know what in god's name the function truly requires for it's functionality? I have come across several times in production code, and more often than not it tends to be a show stopper. 


Avoid them, even if your the only one working on a project. For all you know someone may come by in the future, and need to work on it. Besides though singletons can make code look cleaner, it actually shows extremely bad foresight, and the inability to nail down a coherent, and non-opaque object/function design.


Marcus Hansen

#5292094 What is this artifact in my shadow map?

Posted by on 17 May 2016 - 11:19 AM

Two thoughts come to mind.


Have you tried playing around with the bias? Tweaking it until the issue is not visible on the geometry?

Also, are you using a nullified Sampler State, or did you specify a clamped sampler?


Marcus Hansen

#5290448 XNA Width And Height Problem

Posted by on 06 May 2016 - 11:32 AM

To further elaborate on nscu121978's answer.


"If you request a back-buffer resolution that is not supported by the output device, the XNA Framework automatically selects the highest resolution supported by the output device. For example, if a graphics back buffer with a resolution of 1920×1080 (1080p or 1080i) is created and displayed on a device with 480i resolution, the back buffer automatically is resized to 480i."




This is verbatim from the MSDN website on the use of preferredBackBufferWidth & Height.

Also, it seems there's a general consensus that the ApplyChanges Method should only be called within the update method of your game class, not entirely sure that it matters, but it's worth a shot.


Marcus Hansen

#5289067 triangle culling in close proximity to other triangles?

Posted by on 28 April 2016 - 04:43 AM



haha, it would probably help if I knew what I was looking at ;)


But have you ruled out the possibility of inverted normals on the mesh, with BF culling that would certainly create the issue of triangles not appearing...


Marcus Hansen

#5288014 Going multi-threaded | Batches and Jobs

Posted by on 21 April 2016 - 12:01 PM

Basicly I don't understand what 'Batches' and 'Jobs' are.


What are 'Batches' and 'Jobs' when generally speaking about Thread Pooling?

What are the best way to identify a function call as a 'Batch' or either as a 'Job'?


Hello Julien,


Essentially when he means jobs, he simply is implying work that an engine sub-system has to perform. When he says batch, it's just a conceptualization in the context of the article of a group of individual objects deli-metered based upon some logical segmentation (A BSP Tree perhaps) being submitted to a ThreadPool Queue.


How would one go about creating a multi-thread system?


To my knowledge, C/C++ by itself has no notion of multi-threading. But, here goes a pretty simple example in C, from MSDN, also I'm pretty sure the threading code here is not portable. But, I think Boost does offer a portable solution...



// sample_multithread_c_program.c
// compile with: /c
//  Bounce - Creates a new thread each time the letter 'a' is typed.
//  Each thread bounces a happy face of a different color around
//  the screen. All threads are terminated when the letter 'Q' is
//  entered.

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>

#define MAX_THREADS  32

// The function getrandom returns a random number between
// min and max, which must be in integer range.
#define getrandom( min, max ) (SHORT)((rand() % (int)(((max) + 1) - \
                               (min))) + (min))

int main( void );                    // Thread 1: main
void KbdFunc( void  );               // Keyboard input, thread dispatch
void BounceProc( void * MyID );      // Threads 2 to n: display
void ClearScreen( void );            // Screen clear
void ShutDown( void );               // Program shutdown
void WriteTitle( int ThreadNum );    // Display title bar information

HANDLE  hConsoleOut;                 // Handle to the console
HANDLE  hRunMutex;                   // "Keep Running" mutex
HANDLE  hScreenMutex;                // "Screen update" mutex
int     ThreadNr;                    // Number of threads started
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; // Console information

int main() // Thread One
    // Get display screen information & clear the screen.
    hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
    GetConsoleScreenBufferInfo( hConsoleOut, &csbiInfo );
    WriteTitle( 0 );

    // Create the mutexes and reset thread count.
    hScreenMutex = CreateMutex( NULL, FALSE, NULL );  // Cleared
    hRunMutex = CreateMutex( NULL, TRUE, NULL );      // Set
    ThreadNr = 0;

    // Start waiting for keyboard input to dispatch threads or exit.

    // All threads done. Clean up handles.
    CloseHandle( hScreenMutex );
    CloseHandle( hRunMutex );
    CloseHandle( hConsoleOut );

void ShutDown( void ) // Shut down threads
    while ( ThreadNr > 0 )
        // Tell thread to die and record its death.
        ReleaseMutex( hRunMutex );

    // Clean up display when done
    WaitForSingleObject( hScreenMutex, INFINITE );

void KbdFunc( void ) // Dispatch and count threads.
    int         KeyInfo;

        KeyInfo = _getch();
        if ( tolower( KeyInfo ) == 'a' &&
             ThreadNr < MAX_THREADS )
            _beginthread( BounceProc, 0, &ThreadNr );
            WriteTitle( ThreadNr );
    } while( tolower( KeyInfo ) != 'q' );


void BounceProc( void *pMyID )
    char    MyCell, OldCell;
    WORD    MyAttrib, OldAttrib;
    char    BlankCell = 0x20;
    COORD   Coords, Delta;
    COORD   Old = {0,0};
    DWORD   Dummy;
    char    *MyID = (char*)pMyID;

    // Generate update increments and initial
    // display coordinates.
    srand( (unsigned int) *MyID * 3 );

    Coords.X = getrandom( 0, csbiInfo.dwSize.X - 1 );
    Coords.Y = getrandom( 0, csbiInfo.dwSize.Y - 1 );
    Delta.X = getrandom( -3, 3 );
    Delta.Y = getrandom( -3, 3 );

    // Set up "happy face" & generate color
    // attribute from thread number.
    if( *MyID > 16)
        MyCell = 0x01;          // outline face
        MyCell = 0x02;          // solid face
    MyAttrib =  *MyID & 0x0F;   // force black background

        // Wait for display to be available, then lock it.
        WaitForSingleObject( hScreenMutex, INFINITE );

        // If we still occupy the old screen position, blank it out.
        ReadConsoleOutputCharacter( hConsoleOut, &OldCell, 1,
                                    Old, &Dummy );
        ReadConsoleOutputAttribute( hConsoleOut, &OldAttrib, 1,
                                    Old, &Dummy );
        if (( OldCell == MyCell ) && (OldAttrib == MyAttrib))
            WriteConsoleOutputCharacter( hConsoleOut, &BlankCell, 1,
                                         Old, &Dummy );

        // Draw new face, then clear screen lock
        WriteConsoleOutputCharacter( hConsoleOut, &MyCell, 1,
                                     Coords, &Dummy );
        WriteConsoleOutputAttribute( hConsoleOut, &MyAttrib, 1,
                                     Coords, &Dummy );
        ReleaseMutex( hScreenMutex );

        // Increment the coordinates for next placement of the block.
        Old.X = Coords.X;
        Old.Y = Coords.Y;
        Coords.X += Delta.X;
        Coords.Y += Delta.Y;

        // If we are about to go off the screen, reverse direction
        if( Coords.X < 0 || Coords.X >= csbiInfo.dwSize.X )
            Delta.X = -Delta.X;
            Beep( 400, 50 );
        if( Coords.Y < 0 || Coords.Y > csbiInfo.dwSize.Y )
            Delta.Y = -Delta.Y;
            Beep( 600, 50 );
    // Repeat while RunMutex is still taken.
    while ( WaitForSingleObject( hRunMutex, 75L ) == WAIT_TIMEOUT );

void WriteTitle( int ThreadNum )
    enum {
        sizeOfNThreadMsg = 80
    char    NThreadMsg[sizeOfNThreadMsg];

    sprintf_s( NThreadMsg, sizeOfNThreadMsg,
               "Threads running: %02d.  Press 'A' "
               "to start a thread,'Q' to quit.", ThreadNum );
    SetConsoleTitle( NThreadMsg );

void ClearScreen( void )
    DWORD    dummy;
    COORD    Home = { 0, 0 };
    FillConsoleOutputCharacter( hConsoleOut, ' ',
                                csbiInfo.dwSize.X * csbiInfo.dwSize.Y,
                                Home, &dummy );


So this is pretty simple. While 'q' has not been pressed, and if 'a' has been pressed, and if ntThread is less than 32; increment ntThread, pass the BounceProc function as an argument to the __beginThread() function.


insofar as how to structure this in a typical Game Engine though the article gave some high level insight on it, a deeper explanation on it however would probably be a question best reserved for some other members here, as my only real experience with Multi-Threading was with Java several years ago.


Marcus Hansen

#5281543 Match-3 puzzle game algorithms

Posted by on 16 March 2016 - 02:57 PM


I want a 9X9 grid layout for the game and I would like to have some guidance to design the algorithms to fill up the empty cells of the grid, after match making takes place. I also would like some guidance on how to design the level progression and ramp up the difficulty in a match three puzzle game.


Well I'm not sure how you have your program structured so far (And if you've chosen to have your board represented by a simple array), but code for populating a 1D, or 2D array (in the following example 2D) is quite simple, and can be expressed in many ways. But one simple way is:

//Psuedo Code
Cell board[9][9];
for (i = 0 to board.length())
    for (j = 0 to board.length()) //Assuming your board is 
always column, and row symmetrical
        board[i][j] = new Cell() //where 
your default constructor for cell will just self initialize to be representative 
of an empty cell
        //Or alternatively
        board[i][j] = new 

Of course, I would imagine as Frob sated that populating your board at pure random may lead to cases that as soon as your game loads you get a match 3 Or match 4 without player intervention, which is obviously a sign of either a very liberal, and player friendly Matching game, or a poorly designed one. (I once played a version of bejeweled that upon a level loading I would get Match 4s all over the place, haha, let's just say Wisdom Cat was not amused)


One simple to code game would be TicTacToe. This would give you an idea on how a very basic matching game is created, and potentially provide you with a base to build into a more complex project which ultimately seems like what you want.



#5281260 visual problem with texture tiling

Posted by on 14 March 2016 - 03:35 PM

This is a well know issue. 

One solution would be to flesh out the terrain more, i.e. blend with other textures (A patch of grass that fades into the sand texture?), add supportive meshes (A cactus, a palm tree, a decrepit colonist cart partially devoured by the sand dune, and some ram skulls for good measure ;) ) 


Another one that can be used in conjunction with the previous solution is to use Google! no, haha sorry. But seriously, upon searching your issue in google I found something called Multi-UV mixing which appears to be the result of sampling your base texture with a replica texture at a larger resolution in your shader (I may have butchered that). The results based upon a few articles that I glanced over seem to be something worth looking into


(I'll include the link in the case I completely butchered the idea behind the technique)







#5281211 For beginners

Posted by on 14 March 2016 - 09:28 AM

The only pre-requisite for making games is to have the desire (Programming/Mathematics knowledge is a huge plus). There are plenty of tools out their that will accommodate peoples desires to make games without even a sliver of technical knowledge.


As far as APIs, it REALLY depends on the game your trying to make, the target audience, or if your doing it to amuse yourself. You can make a fun game with console graphics. In fact I remember back in middle school before I learned D3D coding an animated ascii game. In order to accomplish sprite animation I'd do things like this:


char  frOne[] = {' ',' ',' ',' ','*',' ',' ',' '};

char  frTwo[] = {' ',' ',' ',' ',' ','*',' ',' '}; //The asterisk is just moving to the right.


And I would use a simple timer to animate between these char arrays (though my renditions were much more complicated than a star). This produced a result than brought life to my console games.


If you want to make 3D games your best bet is either an engine/framework like Unreal/Unity, or DIY and learn Direct3D11, OpenGL 4.0 APIs (Though the latter APIs are known for their inherent difficulty to learn for beginners, and are not always user friendly, and this list is certainly not exhaustive).


Python is a great language to start out with (A wealth of information, and tutorials are online), it's simple yet powerful. Ambiguous, and extremely flexible. And right off the bat it forces you to indent your code (Which is something I've laughably seen "Advanced" developers overlook). But that's not in stone. There are other good "beginner" languages as well. I started with C, but there was no real reason behind that at the time. I guess I was under the assumption was that it was the only language out their at the time. haha, ignorance can be bliss. 


This page serves to get your IDE environment, and SDK installed.



This page will take you through the Basics.



Just remember games are games. Graphical finesse though important, is not the prime ingredient for making a fun game. A damn good idea implemented well IS however.



#5280699 D3D9 - Rendering image to texture problem

Posted by on 11 March 2016 - 08:10 AM

Welcome to the forums!


First off your not an idiot. A lot of us are still learning here. Though some may disagree; the simple fact that your programming implies that you are capable of logical deduction, and flow control which would imply that you have a high level thought process organically accelerated by a human brain, haha.


That being said the first thing I would check are your renderStates.


without making square for it, so the texture will be just the image?


That's a great question.Your referring to Vectorized graphics which is the use of polygons to represent images/textures in graphics. But, I feel if you check over your RenderStates, or your underlying texture itself you'll find that complete transparency with a image is completely possible, and that the use of vectorized graphics for this one case is a little overkill imho



#5238298 What is the easiest way to show effects(ice, fire, thunder, etc...) in direct...

Posted by on 03 July 2015 - 09:06 PM

It sounds as though you are using a method similar to that of one of the rastertek tutorials for fire. Having implmented it myself it produced an amicable result for a minimal amount of coding/effort.

However, you could try volumetric rendering with spherical billboards. The groundwork for the effect is layed out in ShaderX5, though im sure there is other relevant information to it in other publications.