Advertisement

particle, c++, binding texture

Started by September 17, 2001 07:06 AM
16 comments, last by lunasol 23 years, 5 months ago
You are right Lunatic Raven! I remove the texture load from the constructor and all work fine... What''s the problem with C++ constructor?! In java, constructors are just functions which are called when you create an instance of the object. Does constructor have a different meaning in C++ ?!

lunasol
You have to be doing something wrong.., there''s nothing wrong with loading/binding a texture inside a constructor..
Advertisement
I agree with everyone who says ''it works ok for me''. Things to maybe try:

Is your openGL surface set up before you load/bind textures?
Have you set ''display settings'' prior to load/bind textures?

These are the only circumstances where I have noticed no textures appearing. In the setup I use (windows) I do all the texture loading and display list object building during WM_CREATE handler, after the display settings are changed and the openGL surface is ''initialised''.

Hope that helps. Good luck.
Country: Scotland [not listed in the ''Country'' combobox].
i see what you mean Ken... My particleSystem instance(the class with the problematic constructor) is declared as a global variable. I have 3 cpp files :

main.cpp where ogl stuff is initialized in globals functions.
Demo.cpp where particleSystem is declared
ParticleSystem.cpp where texture loading/binding are done

As "globals variables are initialized at compilation time, and as there is no guaranteed order of initialization between separate compilation units (i.e. .cpp files) "(see http://aips2.nrao.edu/docs/notes/173.text), maybe display setting are not done when particleSystem is initialized...

Thanks for all your replies.

lunasol
An easy fix for you, if you want to initialize everything in the constructor, is to declare the global as a pointer, then, after you know that everything else is ready :
GlobalClass = new CClassType; 


make sure to use

delete CGlobalClass; 


when you are done with it!

Feel free to email me.
[email=JValentine_13@hotmail.com]contact[/email]
When i made one i did something like this.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[loop]->data);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX,TextureImage[loop]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[loop]->data);

InitGL()
{
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);
glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
}
Draw()
{
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_ONE,GL_ONE);
glBindTexture(GL_TEXTURE_2D, texture[9]);

Draw routine();

glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
Advertisement
I tend to agree with Lord Karnus... declare your particle system var as a pointer, and in your initialisation code make the call to new (as LK said)... this will ensure you know exactly when the constructor will get called.

Th other cool thing about having it as a pointer is that if you have a (possibly abstract) base particle system class, and you inherit different types of system from that (ie snow, fire, fountain, etc), you can create and switch them on the fly, still using the one simple call to draw from the base pointer.

Polymorphism rules.

That is all.
One more clue: Is a GL's rendering context properly set up (ie attaced to a device context) before you call ANY OGL func?
I thought this because I had a problem with it and it took me a while to find the bug....

Edited by - _Z on September 23, 2001 1:53:29 PM
0x600

This topic is closed to new replies.

Advertisement