
particle, c++, binding texture
Hi,
few days ago i decided to switch from C to C++. A particle system is to my mind a good way to learn. But i run into a problem dealing with textures. Here we go :
this work :
in main.cpp :
GLuint texId[1];
Particles myParticles;
...
void setTexture(void){
glGenTextures(1,&texId[0]);
....
....
glBindTexture( GL_TEXTURE_2D, texId[0]);
....
}
void draw(void){
glBindTextures(GL_TEXTURE_2D,texId[0]);
myParticles.render();
}
void init(void){
....
setTexture();
....
}
this doesn''t work (the texture is not applied on the particles) :
in main.cpp :
Particles myParticles;
....
void draw(void){
myParticleSystem.render();
}
in particle.cpp :
GLuint texId[1];
Particles:
articles(){
....
this->setTexture();
....
}
void Particles::setTexture(void){
....
glGenTextures(1,&texId[0]);
....
....
glBindTexture( GL_TEXTURE_2D, texId[0]);
....
}
void Particles::render(void){
....
glBindTextures(GL_TEXTURE_2D,texId[0]);
glBegin(GL_TRIANGLE_STRIP);
....
glEnd();
....
}
any clues?
thanks for the replies
learning lunasol

Sorry,but how do you draw the particle, using a quad ? or a triangle? did you forget a texture coordinate setting ?
because i can''t see them in the main gl loop nor the
vertex coords .hope it helps , maybe
(stl sucks)!
because i can''t see them in the main gl loop nor the
vertex coords .hope it helps , maybe
(stl sucks)!
thanks for the reply.
I''m sure that the rendering function is ok either the texcoord. To my mind it is just a problem of texture binding : I just translate the function "setTexture" from main. cpp to particle.cpp
regards,
lunasol
I''m sure that the rendering function is ok either the texcoord. To my mind it is just a problem of texture binding : I just translate the function "setTexture" from main. cpp to particle.cpp
regards,
lunasol
I too am having the same problem, it can't be because of my rendering function, because I've used this code tons of times before, I am now just placing it in a class. With mine, I decided to have a class for textures, but I think there is a problem having the gl calls in a class or something. Either way, I am baffled.
Edited by - Lunatic Raven on September 17, 2001 9:28:15 AM
Edited by - Lunatic Raven on September 17, 2001 9:28:15 AM
"...."
one way of doing this is something like this (out of my head) :
//in the particles class you define a SetupTexture Func.
CParticle::SetupTexture (char* filename)
{
//Load in the file.... Many ways of doing this......
//and then generate it as a texture ....
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,texture.Width, texture.Height, GL_RGB, GL_UNSIGNED_BYTE, texData);
}
//Then in the draw func.
CParticle::Draw()
{
glBindTexture (GL_TEXTURE_2D, texID); //or something like this
(...)
}
Hope this can help you out a little...
Please remember this was take out of my memory....there might be typos or errors....
DON''T CUT & PASTE THIS!!
Take Care!
- -- ---[XaOs]--- -- -
[ project fy ]
//in the particles class you define a SetupTexture Func.
CParticle::SetupTexture (char* filename)
{
//Load in the file.... Many ways of doing this......
//and then generate it as a texture ....
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,texture.Width, texture.Height, GL_RGB, GL_UNSIGNED_BYTE, texData);
}
//Then in the draw func.
CParticle::Draw()
{
glBindTexture (GL_TEXTURE_2D, texID); //or something like this
(...)
}
Hope this can help you out a little...
Please remember this was take out of my memory....there might be typos or errors....
DON''T CUT & PASTE THIS!!

Take Care!
- -- ---[XaOs]--- -- -
[ project fy ]
XaOs:
this is exactly what i''m doing (read the first post
). I call the SetTexture in the constructor. Maybe it''s due to the texture id? How do you declare it? As a member of the class? As a global variable? I try soooo many things that i ''m clueless. Any C++ guru out there?
troubled lunasol
this is exactly what i''m doing (read the first post

troubled lunasol
This may seem a silly question...but...
Have you remembered glEnable(GL_TEXTURE_2D); ??
//with texture mapping code in between
and corresponding glDisable(GL_TEXTURE_2D); ??
As for the c++ parts: variables should be declared in the private section of the class (ideally) with ''get'' & ''set'' functions to access the values from outside that class.
I''m just starting out in this openGL stuff with windows but i''ve got a little experience with c++ and windows. The approach I take is to have a base class that handles all the windows stuff including openGL initialisation and then derive a second class from this that acts as a kind of blank sheet or frame for everything else. All the stuff like textures, display lists etc goes into that derived class. Other classes for specific objects such as image loaders can be declared as member variables of that ''frame'' class. I assume this is the same way everyone does the c++ class thing.
Have you remembered glEnable(GL_TEXTURE_2D); ??
//with texture mapping code in between
and corresponding glDisable(GL_TEXTURE_2D); ??
As for the c++ parts: variables should be declared in the private section of the class (ideally) with ''get'' & ''set'' functions to access the values from outside that class.
I''m just starting out in this openGL stuff with windows but i''ve got a little experience with c++ and windows. The approach I take is to have a base class that handles all the windows stuff including openGL initialisation and then derive a second class from this that acts as a kind of blank sheet or frame for everything else. All the stuff like textures, display lists etc goes into that derived class. Other classes for specific objects such as image loaders can be declared as member variables of that ''frame'' class. I assume this is the same way everyone does the c++ class thing.
Country: Scotland [not listed in the ''Country'' combobox].
Well, I got it working in mine, the only advice I can give is this. OpenGL doesn''t like it when you load the texture in the class''s constructor. OpenGL also doesn''t like it when you call glBindTexture within a class function. All I did was move the texture loading stuff into another member function, then had a function that would return the texID number. Hope this helps.
"...."
Ken Fitlike : thanks for your advices!
Lunatic Raven : i''m happy you''ve resolve your problem (and mine...
) I will try your method ASAP. But ideally, i would load and set textures inside the contructor. It would be perfectly OO!
Any explanation about those strange things (can''t load texture inside a constructor and bind texture inside a class method)?
lunasol
Lunatic Raven : i''m happy you''ve resolve your problem (and mine...

Any explanation about those strange things (can''t load texture inside a constructor and bind texture inside a class method)?
lunasol
quote:
Original post by Lunatic Raven
Well, I got it working in mine, the only advice I can give is this. OpenGL doesn''t like it when you load the texture in the class''s constructor. OpenGL also doesn''t like it when you call glBindTexture within a class function. All I did was move the texture loading stuff into another member function, then had a function that would return the texID number. Hope this helps.
hmmm....strange....it works fine with me!!

I load the texture in a function within the class, and bind the texture within the class!
The texID variable is decleared in the public class, as a private variable!
I use a public class so i can use the main particle class over again without having to adjust it to
what i a working with for every project! Saves me for a lot of writing!

Take Care!
- -- ---[XaOs]--- -- -
[ project fy ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement