Heey,
Thanks all for trying to help me, i solved the problem. and i succesfully run
the following code
Code:
#import "iphoneViewerAppDelegate.h"
#include <osgGA/TrackballManipulator>
#include <osg/ShapeDrawable>
#include <osgViewer/api/IOS/GraphicsWindowIOS>
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/PositionAttitudeTransform>
#include <osgGA/TrackballManipulator>
#include <osg/Geode>
#include <osg/TexGen>
#include <osg/Texture2D>
#define kAccelerometerFrequency 30.0 // Hz
#define kFilteringFactor 0.1
#define SHADER_COMPAT \
"#ifndef GL_ES\n" \
"#if (__VERSION__ <= 110)\n" \
"#define lowp\n" \
"#define mediump\n" \
"#define highp\n" \
"#endif\n" \
"#endif\n"
static const char* vertSource = {
SHADER_COMPAT
"// colors a fragment based on its position\n"
"varying mediump vec4 color;\n"
"void main(void) {\n"
"color = gl_Vertex;\n"
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"}\n"
};
static const char* fragSource = {
SHADER_COMPAT
"varying mediump vec4 color;\n"
"void main(void) {\n"
"gl_FragColor = clamp( color, 0.0, 1.0 );\n"
"}\n"
};
@implementation iphoneViewerAppDelegate
@synthesize _window;
//
//Called once app has finished launching, create the viewer then realize. Can't
call viewer->run as will
//block the final inialization of the windowing system
//
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//get the screen size
CGRect lFrame = [[UIScreen mainScreen] bounds];
unsigned int w = lFrame.size.width;
unsigned int h = lFrame.size.height;
// create the main window at screen size
self._window = [[UIWindow alloc] initWithFrame: lFrame];
//show window
[_window makeKeyAndVisible];
//create our graphics context directly so we can pass our own window
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
// Init the Windata Variable that holds the handle for the Window to
display OSG in.
osg::ref_ptr<osg::Referenced> windata = new
osgViewer::GraphicsWindowIOS::WindowData(_window);
// Setup the traits parameters
traits->x = 0;
traits->y = 0;
traits->width = w;
traits->height = h;
traits->depth = 16; //keep memory down, default is currently 24
traits->red = 33;
traits->blue = 66;
traits->green = 99;
traits->windowDecoration = true;//false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->setInheritedWindowPixelFormat = true;
traits->windowName = "osgViewer";
traits->inheritedWindowData = windata;
// Create the Graphics Context
osg::ref_ptr<osg::GraphicsContext> graphicsContext =
osg::GraphicsContext::createGraphicsContext(traits.get());
graphicsContext->clear();
//create the viewer
viewer = new osgViewer::Viewer();
//if the context was created then attach to our viewer
if(graphicsContext)
{
viewer->getCamera()->setGraphicsContext(graphicsContext);
double w = traits->width;
double h = traits->height;
if(w<h)
h = w;
else
w = h;
viewer->getCamera()->setViewport(new osg::Viewport(0, 0, w , h
));
//
viewer->getCamera()->setProjectionMatrixAsFrustum(-5,5,-5,5,1e-6,1000000);
//
viewer->getCamera()->setProjectionMatrixAsPerspective(30,traits->width/traits->height);
}
osg::setNotifyLevel(osg::INFO);
root = new osg::MatrixTransform();
osg::Geode* geode = new osg::Geode();
osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new
osg::Box(osg::Vec3(1, 1, 1), 1));
geode->addDrawable(drawable);
osg::Program* program = new osg::Program;
program->setName("shader");
program->addShader(new osg::Shader(osg::Shader::VERTEX, vertSource));
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragSource));
geode->getOrCreateStateSet()->setAttributeAndModes(program,
osg::StateAttribute::ON);
root->addChild(geode);
//viewer = new osgViewer::Viewer();
//viewer->setUpViewInWindow(100, 100, 800, 600, 0);
viewer->setSceneData(root.get());
viewer->setCameraManipulator(new osgGA::TrackballManipulator);
viewer->realize();
/*
//if the context was created then attach to our viewer
if(graphicsContext)
{
viewer->getCamera()->setGraphicsContext(graphicsContext);
// viewer->getCamera()->setViewport(new osg::Viewport(0, 0,
traits->width, traits->height));
}
osg::setNotifyLevel(osg::DEBUG_FP);
root = new osg::MatrixTransform();
osg::Geode* geode = new osg::Geode();
osg::ShapeDrawable* drawable = new osg::ShapeDrawable( new
osg::Box(osg::Vec3(0,1,1),1));
drawable->setColor(osg::Vec4(1.0f,0.0f,1.0f,0.5f));
drawable->getOrCreateStateSet();
geode->addDrawable(drawable);
root->addChild(geode);
viewer->setSceneData(root.get());
viewer->setCameraManipulator(new osgGA::TrackballManipulator);
viewer->realize();
*/
[NSTimer scheduledTimerWithTimeInterval:1.0/5.0 target:self
selector:@selector(updateScene) userInfo:nil repeats:YES];
//Configure and start accelerometer
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(0.01)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
}
//
//Timer called function to update our scene and render the viewer
//
static bool flag = false;
- (void)updateScene {
viewer->frame();
if(flag)
{
viewer->getCamera();
}
else
{
}
flag = !flag;
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
-(void)applicationWillTerminate:(UIApplication *)application{
root = NULL;
viewer = NULL;
}
//
//Accelorometer
//
- (void)accelerometer:(UIAccelerometer*)accelerometer
didAccelerate:(UIAcceleration*)acceleration
{
//Use a basic low-pass filter to only keep the gravity in the accelerometer
values
accel[0] = acceleration.x * kFilteringFactor + accel[0] * (1.0 -
kFilteringFactor);
accel[1] = acceleration.y * kFilteringFactor + accel[1] * (1.0 -
kFilteringFactor);
accel[2] = acceleration.z * kFilteringFactor + accel[2] * (1.0 -
kFilteringFactor);
}
- (void)dealloc {
root = NULL;
viewer = NULL;
[super dealloc];
}
@end
The problem was in OpenSceneGraph latest version (the one that under work now)..
anyway.. i want to share with you how i solve it.
first ShaderGen.h in OsgUtil not support shaders in OpenGLES 2.0 for now. its
seem it support for OpenGL 2.0 just ..
so the first thing i done, that i put my own shaders..
then i run it, and fields. i was using iOS 3.2 SDK ..
when i changed it to iOS 4.0 SDK.. it magically Worked :D.. Wooohooo..
finally i get results.. but still there is another issuess i must solve but for
now.. its good..
i hope this information will be useful for someone
thanks all for your support and help.
...
Thank you!
Cheers,
Laith[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35120#35120
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org