C++ and OpenGL problem

Soldato
Joined
7 Nov 2007
Posts
6,833
Location
Required
Hi there,

Working through Beginning OpenGL Game Programming and I want to add a TGA mouse cursor. Most of it is sorted, but there's a problem I'm having.

winmain.cpp has the mouseX and mouseY variables. I have taken these out of the winmain.cpp file and put them in a header called mouse.h which I have included at the top of the file. All hunky dory.

Now, I want to use the same mouseX and mouseY variables in another file. Can I do this? Do I need to have a separate routine to find the mouse's X and Y values in CGfxOpenGL.cpp? Using mouse.h gives me this:

error: 'mouseX' was not declared in this scope
error: 'mouseY' was not declared in this scope

Not sure what to do here guys? :)
 
Got it working now! Declared them as external variables in the header file:

extern int mouseX, mouseY;

Then in winmain initialised them equal to 0.

Now to find out how to get this cursor transparent...
 
If i'm reading your problem right what you should do is:

Write an accessor/mutator for mouse x and y, then simply create an instance of your 'mouse' class in the class you want to use those variables in.

So basically:

private float _mouseX, _mouseY;

void SetMouseX(float mouseX)
{
_mouseX = mouseX;
}

float GetMouseX()
{
return _mouseX;
}

(you should probably return by const reference with the getter ^^).

Then where you want to use them just make a new instance of mouse (i.e Mouse _mouse) then you can do _mouse.setMouseX etc.
 
Last edited:
Thanks for that. I'm a little confused at the minute, coming from C to C++ means I haven't fully grasped things yet. Probably sleep on it and come back to it in the morning.

Cheers anyway! :)
 
Back
Top Bottom