-
Of course, I don't know how the program looks, but something like a graphics context and a few things like active textures might be global, but the class itself should certainly not set it.
When using global variables, don't forget to use const-correctness.
-
what?
edit: ah i shell use an external function to set the active. why didnt i came to this idee *lol* :D
-
You can use an object to keep track of your graphics context. You could make it global.
The class for this should have pointers for the active texture, for example and you can set/get it with appropriate functions in the class itself.
This or something in lines with it what I believe mats is suggesting.
-
Yes, I agree with Elysia - one, perhaps global, graphics context that "ties everything else up" is the common way to do graphics implementations.
--
Mats
-
thats what i tried and it caused several errors:
Code:
// Somewhere in the example:
vglTexture tex;
tex.LoadFromFile("Media/Texture2.bmp");
vglBindTexture(tex);
// Declaration of vglTextur:
vglTexture *vglTextur;
// Somewhere in the code:
void vglBindTexture(vglTexture tex) {
vglTextur = &tex;
}
-
What do you this code does? It makes a copy of your texture and then assigns the address of it to a global pointer. But when the function exits, that copy is gone. Destroyed. Oops.
Suggest you try what was outlined above.
-
i'm a newbee and i dont understand it :(:(:(
-
The incoming variable of "tex" in vglBindTexture() is a local copy of the object. Then you assign a global variable with the address of this variable, and leave the function - the local copy no longer exist.
You can fix it by making the vglBindTexture take a pointer, and pass the address of your texture.
--
Mats
-
You have no idea what passing by-value, by-pointer or by-reference is and you didn't know how to make a class and you're playing around with graphics and classes?
I think you need to go back and try to learn a little more basics.
Without proper basics, you won't get far.