Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 15 Jun 2007
Offline Last Active Today, 06:39 PM

#5147807 Is there a way to break out of an if statement without "hacking the code...

Posted by Vortez on 17 April 2014 - 09:45 PM

Your approach seem a bit hackish if you want my opinion. Perhaps you should refactor and encapsulate more code into classes that would take care of the leveling up process and manage the player health ect? Your code is very  hard to read/understand atm to be honest. You might consider splitting those things up into functions.

#5147250 WM_INPUT with Arrow Keys Failing

Posted by Vortez on 15 April 2014 - 08:46 PM

Does the debugger get triggered if you put a breakpoint on the line


USHORT key=raw->data.keyboard.VKey;


and press the arrow key? If so, what's the VKey value?


I never used rawinput, so i can't help you much. Just saying (i know, im an optimization freak smile.png ), you can replace

if(raw->data.keyboard.Flags == 0)


face_right = raw->data.keyboard.Flags == 0 ? 1 : 0;

And hum, you don't need to redefine those key, they're already defined as VK_RIGHT and VK_D respectively.

#5147171 Need help to draw cursor properly

Posted by Vortez on 15 April 2014 - 12:39 PM

Seem like i solved it, i just had to substract the hotspot from the cursor location, and remove the width and height from the DrawIconEx() call

void CScreenshot::DrawScreenCursor(HDC hDC)
	POINT CursorPos;
	CursorInfo.cbSize = sizeof(CURSORINFO);

	ZeroMemory(&IconInfo, sizeof(ICONINFO));
	GetIconInfo((HICON)CursorInfo.hCursor, &IconInfo);

	int x = CursorPos.x - IconInfo.xHotspot;
	int y = CursorPos.y - IconInfo.yHotspot;

	DrawIconEx(hDC, x, y, CursorInfo.hCursor, 0, 0, 0, NULL, DI_NORMAL);

#5146774 Paul Nettle's memory tracker mmgr and C++11

Posted by Vortez on 13 April 2014 - 04:29 PM

What difference does it make if you just don't use TestClass() = delete; ? I mean, i've written code just fine for years without ever using this and it work. What's the point of deleting a constructor? I don't get it.


EDIT: I think i understand now, it's to force using the constructor with the parameter isn't it?


Maybe this would work?

#ifdef _DEBUG
    // ---------------------------------------------------------------------------------------------------------------------------------
    // Variations of global operators new & delete
    // ---------------------------------------------------------------------------------------------------------------------------------
    void	*operator new(size_t reportedSize);
    void	*operator new[](size_t reportedSize);
    void	*operator new(size_t reportedSize, const char *sourceFile, int sourceLine);
    void	*operator new[](size_t reportedSize, const char *sourceFile, int sourceLine);
    void	operator delete(void *reportedAddress);
    void	operator delete[](void *reportedAddress);
    // ---------------------------------------------------------------------------------------------------------------------------------
    // Macros -- "Kids, please don't try this at home. We're trained professionals here." :)
    // ---------------------------------------------------------------------------------------------------------------------------------
    #include "nommgr.h"
    #define	new	(m_setOwner (__FILE__,__LINE__,__FUNCTION__),false) ? NULL : new
    #define	delete	(m_setOwner (__FILE__,__LINE__,__FUNCTION__),false) ? m_setOwner("",0,"") : delete
    #define	malloc(sz)	m_allocator (__FILE__,__LINE__,__FUNCTION__,m_alloc_malloc,sz)
    #define	calloc(sz)	m_allocator (__FILE__,__LINE__,__FUNCTION__,m_alloc_calloc,sz)
    #define	realloc(ptr,sz)	m_reallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_realloc,sz,ptr)
    #define	free(ptr)	m_deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr)

    class TestClass
#ifdef _DEBUG
    TestClass() = delete;
    TestClass(int i) { }
    virtual ~TestClass() { cout << "Destructor called." << endl; }

#5146457 How to cap speed of a moving object

Posted by Vortez on 11 April 2014 - 10:41 PM

Perhaps a simple


if(speed > limit)

    speed = limit;



#5146409 Playing a video in OpenGL

Posted by Vortez on 11 April 2014 - 05:16 PM

You could take a look at this tutorial from nehe, a bit outdated but it still work. Otherwise, you need to find a library that can decompress the video frame and render those as texture.

#5145887 how do i capture the screen with the windows api?

Posted by Vortez on 10 April 2014 - 04:10 AM

Well, you are lucky cause i just finished working on a similar project. I don't really feel like rewriting it so you gonna have to take what you can from the code and adapt it to yours. Note that this code support all bit per pixels a bitmap can have(except 24), but you probably only need the 32 or 24 bit one, so just ignore the palette stuffs. Also, ignore the FillScreenshotInfo() and CreateEmpty() functions, but FillBMIHeader() is important to keep. You might also need this code for the cursor part, and this class to calculate the buffer size required for the bitmap(It return the 4-bytes aligned size needed).


Actually, here's a more simple version of the code, but i can't garanty it is 100% bug free (might be missing a ReleaseDC() somewhere, or not).

#5145450 raw input mouse problem

Posted by Vortez on 08 April 2014 - 01:02 PM

Just a little sidenote on you're message loop, this:

		if(message.message == WM_QUIT)
			return false;

Can be reduced to this:

		if(message.message == WM_QUIT)
			return false;


#5144419 raw input mouse problem

Posted by Vortez on 04 April 2014 - 01:19 PM

Well, since windows only receive mouse message when the mouse cursor change position, it's logical that lastx and lasty will almost never be 0. I guess the solution would be to save those yourself, into some variables, each time your polling the inputs.

#5142453 MSVS's preprocessor vs gcc's preprocessor

Posted by Vortez on 26 March 2014 - 08:55 PM

Did you at least tryed to read this??? Or look at this??? Can you post more than one sentence per post??? If you want to be serious about programming, you have to learn to solve problem on your own sometime. We can help but we can't hold your hand every time a little problem arise.


Also, do you really need that GLTool.h? It might be usefull to follow some example in the book, but im pretty sure most of the code can work without it, or with similar code. Beside, that's not like this is the only ressource to learn from. Most of the time when i see files like that, i just ignore them and try to do without them to be honest. What will you do when you work in the industry? Ask everyone to use GLTool.h because that's what you used at school and can't do without it? Like i said, it's nice to learn from that book but far from indispensable.


There's a fully compiled example here for vs 2010, and before you tell me vs is crap like in you other posts, well it's not, and at least you don't have to work with the command line, which is IMO really, really outdated (i dont get why ppl still compile in command line for anything except assembly...) Another thing that annoy me with your book is that it uses it's own OpenGL headers and libraries files, and they're in the same folder as the default one(for visual studio at least) so it complicate the projects setup a bit (ie: you might have to rename the existing folder or files for example to make the code work properly, or move them, or whatever...)

#5141170 Why are my two classes sharing variables? C++

Posted by Vortez on 22 March 2014 - 12:24 AM

Are you sure you don't have some globals variables named exactly like in your classes or something? I can't see anything wrong with the code, maybe i am missing something... also the bug might be elsewhere, who knows. Did you tried debugging it? The error shoud be pretty oblivious, find what's changing the enemy location when shooting the sword.

#5140170 Trouble Calculating Normals

Posted by Vortez on 18 March 2014 - 07:00 PM

I noticed also in your first example, you are calling glTexCoordPointer(2, GL_FLOAT, 0, UV_Coords); without first calling glEnableClientState, and i dont see what glBlend had to do with normals. My guess is some of your triangles are drawn in the wrong order, (clockwise or counterclockwise, i never remember wich one is used by default, but they should all use the same winding order)

#5140164 Could someone explain this?

Posted by Vortez on 18 March 2014 - 06:18 PM

And this:

int main()


Are you trolling now? Because, i can't tell if you are or if this is a question.

#5139884 c# game

Posted by Vortez on 17 March 2014 - 09:18 PM

Yea, don't use gdi. I started directly in opengl and it turned out just fine. Most people however would recommend something simpler like sdl or something. Nothing wrong with starting with c# either, it just won't be hardware accelerated and double buffered(although there a workaround for that), in other words, it's good for 2d games. Some even start with console programming. I guess it's up to you to decide what's best. Working with gdi in general is just a pain to be frank and i wouldn't recommend it especially if you're just starting out. Unity could be a good option too, from what i've heard, never tried it so i cant say a lot on it.

#5139583 Needing some quick tips on how to organize my code

Posted by Vortez on 16 March 2014 - 06:59 PM

What i would do is create the Map class and let it handle the drawing, then i might add it to the GraphicManager later on, and access it from there.

The truth is, there is no perfect answer to this, but the map class should be responsible to draw the map (and do other map related stuffs) and nothing more.


Blit? what api are you using to draw your stuff? I generally just let a function called RenderScene() to do all the rendering to be honest, which call other classes or functions to draw the different parts of the scene.


Here's a small sample of my main drawing routine of an old game of mine

			// Disable lightning + depth test

			// Draw the sky

			// Enable lightning + depth test

			// Draw solid objects
			// Render chess board
			// Render chess pieces
			// Draw transparent objects
			// Check the sun visibility status
			pCam->SunVisStatus = DoLensFlareTests(pCam);

			// Generate the shadows effects
				if(Menus.Options.ShadowMode == SHADOW_SIMPLE){
				} else {

This is just to give you an idea. As you can see, i havent splitted objects into class, i just wrote a function to handle each of them, but it's an old game, today i might do this differently, but this was the simplest solution i though of at the time. I do however usually use a menu class to draw menu related stuff (not shown here).


Maybe you should start writting it in a more functionnal way, then refactor it later into classes, since you look a bit lost on what you are trying to achieve.

OOP is great, but it's a bit hard to get everything right the first time to be honest.