コード例 #1
0
	static TQ3ViewObject QD3DSupport_NewView(HWND theWindow)
#endif
{
	TQ3Status				myStatus;
	TQ3ViewObject			myView;
	TQ3DrawContextObject	myDrawContext;
	TQ3RendererObject		myRenderer;
	TQ3GroupObject			myLights;
	TQ3CameraObject			myCamera;
#if TARGET_OS_WIN32
	RECT					clientRect;
	BOOL					success;
#endif


		myView = Q3View_New();
		if (myView == nil)
		{
			goto bail;
		}

		//	Create and set draw context.
		if ((myDrawContext = QD3DSupport_NewDrawContext(theWindow)) == nil )
		{
			goto bail;
		}
			
		if ((myStatus = Q3View_SetDrawContext(myView, myDrawContext)) == kQ3Failure )
		{
			goto bail;
		}

		Q3Object_Dispose( myDrawContext ) ;
		
		//	Create and set renderer.
		
		// this would use the Z-Buffer renderer
	#if 0

		myRenderer = Q3Renderer_NewFromType(kQ3RendererTypeWireFrame);
		if ((myStatus = Q3View_SetRenderer(myView, myRenderer)) == kQ3Failure ) {
			goto bail;
		}
		
	#else

		// this would use the interactive software renderer

		if ((myRenderer = Q3Renderer_NewFromType(kQ3RendererTypeInteractive)) != nil )
		{
			if ((myStatus = Q3View_SetRenderer(myView, myRenderer)) == kQ3Failure )
			{
				goto bail;
			}
			// these two lines set us up to use the best possible renderer,
			// including  hardware if it is installed.
			Q3InteractiveRenderer_SetDoubleBufferBypass (myRenderer, kQ3True);						
			Q3InteractiveRenderer_SetPreferences(myRenderer, kQAVendor_BestChoice, 0);

		}
		else
		{
			goto bail;
		}
	#endif

		Q3Object_Dispose( myRenderer ) ;
		
		//	Create and set camera.
		#if TARGET_OS_MAC
			if ( (myCamera = QD3DSupport_NewCamera((float) (theWindow->portRect.right - theWindow->portRect.left),
													(float) (theWindow->portRect.bottom - theWindow->portRect.top))) == nil )
			{
				goto bail;
			}
		#else if TARGET_OS_WIN32
			success = GetClientRect(theWindow, &clientRect);
			if (success)
			{
				if ( (myCamera = QD3DSupport_NewCamera((float)RECT_WIDTH(clientRect), (float)RECT_HEIGHT(clientRect))) == nil )
				{
					goto bail;
				}
			}
			else
			{
				goto bail;
			}
		#endif
			
		if ((myStatus = Q3View_SetCamera(myView, myCamera)) == kQ3Failure )
		{
			goto bail;
		}
		Q3Object_Dispose( myCamera ) ;
		
		//	Create and set lights.
		if ((myLights = QD3DSupport_NewLights()) == nil )
		{
			goto bail;
		}
			
		if ((myStatus = Q3View_SetLightGroup(myView, myLights)) == kQ3Failure )
		{
			goto bail;
		}
			
		Q3Object_Dispose(myLights);

		//	Done!!!
		return ( myView );
		
	bail:
		//	If any of the above failed, then don't return a view.
		return ( nil );
}
コード例 #2
0
TQ3ViewObject MyNewView(DocumentPtr theDocument)
{
	TQ3Status				myStatus;
	TQ3ViewObject			myView;
	TQ3DrawContextObject	myDrawContext;
	TQ3RendererObject		myRenderer;
	TQ3CameraObject			myCamera;
	TQ3GroupObject			myLights;
	
	myView = Q3View_New();
	
	//	Create and set draw context.
	switch( theDocument->drawcontextType ) 
	{
	case kQ3DrawContextTypeWin32DC:
		if ((myDrawContext = NewWin32DCDrawContext(theDocument)) == NULL )
			goto bail;
		break;
 	case kQ3DrawContextTypeDDSurface:
		goto bail;	/* TBD */
	
	default:
	case kQ3DrawContextTypePixmap:
		if ((myDrawContext = NewPixmapDrawContext(theDocument, theDocument->fPixelFormat )) == NULL )
			goto bail;
		break;
	}
		
	if ((myStatus = Q3View_SetDrawContext(myView, myDrawContext)) == kQ3Failure )
		goto bail;

	Q3Object_Dispose( myDrawContext ) ;
	
	//	Create and set renderer.
	switch( theDocument->rendererType ) 
	{
	case kQ3RendererTypeWireFrame: // this uses the wire frame renderer
		myRenderer = Q3Renderer_NewFromType(kQ3RendererTypeWireFrame);
		if ((myStatus = Q3View_SetRenderer(myView, myRenderer)) == kQ3Failure ) {
			goto bail;
		}
		break;
	default:
	case kQ3RendererTypeInteractive: // this uses the interactive renderer
		if ((myRenderer = Q3Renderer_NewFromType(kQ3RendererTypeInteractive)) != NULL ) {
			if ((myStatus = Q3View_SetRenderer(myView, myRenderer)) == kQ3Failure ) {
				goto bail;
			}
			// these two lines set us up to use the best possible renderer,
			// including  hardware if it is installed.
			Q3InteractiveRenderer_SetDoubleBufferBypass (myRenderer, kQ3True);						
			Q3InteractiveRenderer_SetPreferences(myRenderer, kQAVendor_BestChoice, 0);
		}
		else {
			goto bail;
		}
		break;
	}

	Q3Object_Dispose( myRenderer ) ;
	
	//	Create and set camera
	if ( (myCamera = MyNewCamera(theDocument)) == NULL )
		goto bail;
		
	if ((myStatus = Q3View_SetCamera(myView, myCamera)) == kQ3Failure )
		goto bail;

	Q3Object_Dispose( myCamera ) ;
	
	//	Create and set lights
	if ((myLights = MyNewLights()) == NULL )
		goto bail;
		
	if ((myStatus = Q3View_SetLightGroup(myView, myLights)) == kQ3Failure )
		goto bail;
		
	Q3Object_Dispose(myLights);

	return ( myView );
	
bail:
	//	If any of the above failed, then don't return a view.
	return ( NULL );
}
コード例 #3
0
// Returns whether the creation was a success
bool CreateTriangulator(void)
{
	// No need to create it more than once
	if (TriangulatorView) return true;
	
	TriangulatorClass =
		Q3XObjectHierarchy_RegisterClass(
			kQ3SharedTypeRenderer,
			&TriangulatorClassType,
			"BG-Inspired Triangulator",
			TriangulatorMetaHandler,
			NULL, 0, 0);
	
	if(!TriangulatorClass) return false;
	if(!TriangulatorClassType) return false;
	
	// Dummy draw context: a pixmap (image buffer) that is empty
	TQ3PixmapDrawContextData PixmapContextData =
	{
		// drawContextData
		{
			kQ3ClearMethodWithColor,
			{0,0,0,0},
			{{0,0},{0,0}},
			kQ3False,
			NULL,
			kQ3False,
			kQ3True
		},
		// pixmap
		{
			NULL,
			0,
			0,
			0,
			32,
			kQ3PixelTypeARGB32,
			kQ3EndianBig,
			kQ3EndianBig
		}
	};
	
	TQ3DrawContextObject DrawContextObject = Q3PixmapDrawContext_New(&PixmapContextData);
	if (!DrawContextObject) return false;
	
	TQ3RendererObject RendererObject = Q3Renderer_NewFromType(TriangulatorClassType);
	if (!RendererObject)
	{
		Q3Object_Dispose(DrawContextObject);
		return false;
	}
	
	TriangulatorView = Q3View_New();
	bool Success = TriangulatorView != NULL;
	if(Success)
		Success = (Q3View_SetDrawContext(TriangulatorView, DrawContextObject) == kQ3Success);
	if(Success)
		Success = (Q3View_SetRenderer(TriangulatorView, RendererObject) == kQ3Success);
	
	// No longer needed	
	Q3Object_Dispose(DrawContextObject);
	Q3Object_Dispose(RendererObject);
	return Success;
}