I am using osg in the MFC simple document application,and now I want to draw
ocean in the window,in fact there is a plugin called osgocean which can draw
ocean perfectly.but it not satisfied my need,because I should treat the ocean
as a osg node for the further process. I look for the info in the Internet and
find many resoults drawing ocean in opengl,I also find how to use opengl in the
osg. these are my codes:
first impliment the class for using opengl in OSG:
class SimpleOceanDrawCallBack
:public osg::Drawable::DrawCallback
{
public:
SimpleOceanDrawCallBack(void);
~SimpleOceanDrawCallBack(void);
virtual void drawImplementation(osg::RenderInfo& renderInfo,const
osg::Drawable* drawable ) ;
};
second use the defined class(SimpleOceanDrawCallBack) when necessary:
osg::ref_ptr<osg::Geometry> geometry=new osg::Geometry;
geometry->setUseDisplayList(false);
geometry->setDrawCallback(new OceanDrawCallBack());
osg::ref_ptr<osg::Geode> geode=new osg::Geode;
geode->addDrawable(geometry);
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
and then the geode node the the "ocean" node I needed ,I can do something
else on this node, the body of drawImplementation is the process of drawing
ocean , now is the main issue:
when drawImplementation is simple the class works well:
void SimpleOceanDrawCallBack::drawImplementation(osg::RenderInfo&
renderInfo,const osg::Drawable* drawable ) {
static double dColor= 50;//????
glColor3f( dColor, 0, 0);
glBegin(GL_TRIANGLES);//??OSG????????opengl??????
glVertex3f( 0.0, 0.0, 0.0);
glVertex3f( 2.0, 0.0, 0.0);
glVertex3f( 0.0, 0.0, 2.0);
glEnd();
dColor += 1;//????????
if ( dColor > 255)
{
dColor= 0.0;
}
}
It works well and will drawing a triangle in the window ,But when I use
the drawing ocean example I failed ,these are the drawing ocean procedure:
first I need to do some initialized things,so I put some codes in the
construction function:
OceanDrawCallBack::OceanDrawCallBack(void)
{
int argc = 1;
char *argv[1] = {(char*)"Something"};
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("Ocean");
glutCreateMenu(NULL);
// //glutDisplayFunc(redisplayFunc);
// //glutReshapeFunc(reshapeFunc);
// //glutKeyboardFunc(keyboardFunc);
// //glutSpecialFunc(specialKeyFunc);
// //glutMouseFunc(mouseClickFunc);
// //glutMotionFunc(mouseMotionFunc);
// //glutPassiveMotionFunc(mousePassiveMotionFunc);
// //glutIdleFunc(idleFunc);
glewInit();
GLuint transmittanceTex;
GLuint irradianceTex;
GLuint inscatterTex;
float *data = new float[16*64*3];
FILE *f = fopen("data/irradiance.raw", "rb");
fread(data, 1, 16*64*3*sizeof(float), f);
fclose(f);
glActiveTexture(GL_TEXTURE0 + IRRADIANCE_UNIT);
glGenTextures(1, &irradianceTex);
glBindTexture(GL_TEXTURE_2D, irradianceTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, 64, 16, 0, GL_RGB,
GL_FLOAT, data);
delete[] data;
.......
}
then it can complile well ,but I see nothing in the window.and when I delete
some code(the glutInit function):
OceanDrawCallBack::OceanDrawCallBack(void)
{
// int argc = 1;
// char *argv[1] = {(char*)"Something"};
// glutInit(&argc, argv);
// glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
// glutInitWindowSize(width, height);
// glutCreateWindow("Ocean");
// glutCreateMenu(NULL);
// //glutDisplayFunc(redisplayFunc);
// //glutReshapeFunc(reshapeFunc);
// //glutKeyboardFunc(keyboardFunc);
// //glutSpecialFunc(specialKeyFunc);
// //glutMouseFunc(mouseClickFunc);
// //glutMotionFunc(mouseMotionFunc);
// //glutPassiveMotionFunc(mousePassiveMotionFunc);
// //glutIdleFunc(idleFunc);
glewInit();
GLuint transmittanceTex;
GLuint irradianceTex;
GLuint inscatterTex;
float *data = new float[16*64*3];
FILE *f = fopen("data/irradiance.raw", "rb");
fread(data, 1, 16*64*3*sizeof(float), f);
fclose(f);
glActiveTexture(GL_TEXTURE0 + IRRADIANCE_UNIT);
glGenTextures(1, &irradianceTex);
glBindTexture(GL_TEXTURE_2D, irradianceTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, 64, 16, 0, GL_RGB,
GL_FLOAT, data);
delete[] data;
.......
}
it complile well and but runs error in this function of mfc:
BOOL AFXAPI AfxDeactivateActCtx(DWORD dwFlags, ULONG_PTR ulCookie)
{
BOOL rc = pfnDeactivateActCtx != 0 ? pfnDeactivateActCtx(dwFlags,
ulCookie) : FALSE;
return rc;
}
then I debug the program and find the it jump in the error in this line:
glActiveTexture(GL_TEXTURE0 + IRRADIANCE_UNIT);
this code is just active the texture unit ,and why result in the problem,or is
my method is wrong ? I could not use opengl in the osg in such way?then what
should I do to draw ocean as a node in osg?_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org