Hi All,
I'm Software Engineer,
and here in the company we are trying our product to IPhone/IPad.

anyway. after near to 1 month of search ,  modifying and fixing i didnt find 
any answer to my problems Problems In Open Scene Graph.

Here Is the Problem.
im trying to run the following code :
its very simple project that "should" show box on the screen , but the problem 
it is not showing else the background.. and search i found that there is a 
shader compiling errors in open scene graph :S. i fix it. and still nothing 
appear else the background... note i wrote a test that just change the 
background color to see if the problem is from opengles linking or something 
like.. and its work correctly..

guys i really need help..
do anyone have any idea about what is going on.


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

@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 = 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);
        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());
    
        [NSTimer scheduledTimerWithTimeInterval:1.0/5.0 target:self 
selector:@selector(updateScene) userInfo:nil repeats:YES]; 
    
    //Configure and start accelerometer
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(0.1)];
    [[UIAccelerometer sharedAccelerometer] setDelegate:self];
}
//
//Timer called function to update our scene and render the viewer
//
- (void)updateScene {
        viewer->frame();
}
- (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





... 

Thank you!

Cheers,
Laith

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35067#35067





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to