Esempio n. 1
0
//************************************
// Method:    Init
// FullName:  QuackWin::Init
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: void
// Description: Platform specfic OpenGL initialization. Loads OpenGL, inits,
// creates the window, etc. If this call is successful, a functional OpenGL
// subsystem has been established.
//************************************
void QuackWin::Init(void) {
	// init opengl
	StartOpenGL();

	// other init functions
	glewInit();
}
Esempio n. 2
0
HRESULT __stdcall SpoutSenderPlugin::OnStart()
{
	
	StartOpenGL(); // Initialize openGL if not already
	bSpoutOut = true;

	return NO_ERROR;
}
Esempio n. 3
0
HRESULT __stdcall SpoutSenderPlugin::OnStart()
{
	// printf("OnStart()\n");
	StartOpenGL(); // Initialize openGL if not already
	spoutsender.SetDX9(true); // To use DirectX 9 we need to specify that first
	bSpoutOut = true;

	return NO_ERROR;
}
Esempio n. 4
0
// use this function to render the GL surface on the device, using any modification you want
// return S_OK if you actually draw the texture on the device, or S_FALSE to let VirtualDJ do it
// if using VDJPLUGINFLAG_VIDEOINPLACE, texture and vertices will be NULL
HRESULT __stdcall SpoutSenderPlugin::OnDraw()
{
	TVertex *vertices;

	// Quit if OpenGL initialization failed
	if(!bOpenGL) { 
		DrawDeck(); 
		return S_OK; 
	}

	// Activate the shared context for draw
	// This can fail if the video window is closed and re-opened
	// Possibly because the dc that was orginally used is gone
	// It will start again if the start button is toggled
	// but calling StartOpenGL here seems to work OK.
	if(!wglMakeCurrent(m_hdc, m_hSharedRC)) {
		// printf("wglMakeCurrent 1 fail\n");
		bOpenGL = false;
		StartOpenGL(); // Initialize openGL again
		return S_OK;
	}

	// In order to draw the original image, you can either just call DrawDeck()
	// if you don't need to modify the image (for overlay plugins for examples),
	// or call GetTexture to get low-level access to the texture and its vertices.

	// Get the DX9 device
	GetDevice(VdjVideoEngineDirectX9, (void **)&d3d_device);
	if(d3d_device) {

		// Get the Virtual DJ texture and description
		GetTexture(VdjVideoEngineDirectX9, (void **)&dxTexture, &vertices);
		dxTexture->GetLevelDesc(0, &desc);
		if(!dxTexture) {
			DrawDeck(); // Let VirtualDJ do the drawing
		    return S_OK;
		}

		// Is Spout initialized yet ?
		if(!bInitialized) {
			m_Width = desc.Width;
			m_Height = desc.Height;

			// This is a sender so create one
			sprintf_s(SenderName, 256, "VirtualDJ Spout Sender");

			// To use DirectX 9 we need to specify that first
			spoutsender.SetDX9(true);

			// And we also have to set the shared texture format as D3DFMT_X8R8G8B8 so that receivers know it
			// because the default format argument is zero and that assumes D3DFMT_A8R8G8B8
			if(spoutsender.CreateSender(SenderName, m_Width, m_Height, (DWORD)D3DFMT_X8R8G8B8)) {
				// printf("Created sender [%s]\n", SenderName);
				bInitialized = true;
			}


		}
		else if(m_Width != desc.Width || m_Height != desc.Height) {

			// Initialized but has the texture changed size ?
			m_Width = desc.Width;
			m_Height = desc.Height;

			// Update the sender	
			spoutsender.UpdateSender(SenderName, m_Width, m_Height);

		}
		else if(bSpoutOut) { // Initialized and plugin has started

			// Copy from video memory to system memory
			hr = d3d_device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &source_surface, NULL);
			if(SUCCEEDED(hr)) {
				
				// Get the Virtual DJ texture Surface
				hr = dxTexture->GetSurfaceLevel(0, &texture_surface);

				if(SUCCEEDED(hr)) {
					// Copy Surface to Surface
					hr = d3d_device->GetRenderTargetData(texture_surface, source_surface);	
					if(SUCCEEDED(hr)) {
						// Lock the source surface using some flags for optimization
						hr = source_surface->LockRect(&d3dlr, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY);
						if(SUCCEEDED(hr)) {
							source_surface->GetDesc(&desc);
							// Pass the pixels to spout
							// Disable invert of texture because this is a DirectX source
							// 4-byte alignment might need checking
							if(desc.Format == D3DFMT_X8R8G8B8) { // We have initialized the sender for this format
								spoutsender.SendImage((unsigned char *)d3dlr.pBits, desc.Width, desc.Height, GL_BGRA_EXT, true, false);
							}
							source_surface->UnlockRect();
						}
					}
				}
			}

			if(texture_surface) texture_surface->Release();
			if(source_surface) source_surface->Release();
			texture_surface = NULL;
			source_surface = NULL;

		}
	}

	DrawDeck(); // Draw the image coming in

	return S_OK;

}
Esempio n. 5
0
HRESULT __stdcall SpoutSenderPlugin::OnDraw()
{
	TVertex *vertices;

	// Quit if OpenGL initialization failed
	if(!bOpenGL) { 
		DrawDeck(); 
		return S_OK; 
	}

	// Activate the shared context for draw
	// This can fail if the video window is closed and re-opened
	// Possibly because the dc that was orginally used is gone
	// It will start again if the start button is toggled
	// but calling StartOpenGL here seems to work OK.
	if(!wglMakeCurrent(m_hdc, m_hSharedRC)) {
		bOpenGL = false;
		StartOpenGL(); // Initialize openGL again
		return S_OK;
	}

	// Get the DX9 device
	GetDevice(VdjVideoEngineDirectX9, (void **)&d3d_device);
	if(d3d_device) {

		// Get the Virtual DJ texture and description
		GetTexture(VdjVideoEngineDirectX9, (void **)&dxTexture, &vertices);
		if(!dxTexture) {
			DrawDeck(); // Let VirtualDJ do the drawing
		    return S_OK;
		}
		dxTexture->GetLevelDesc(0, &desc);

		// Is Spout initialized yet ?
		if(!bInitialized) {
			m_Width = desc.Width;
			m_Height = desc.Height;
			// This is a sender so create one
			sprintf_s(SenderName, 256, "VirtualDJ Spout Sender");
			// The default format argument is zero and that assumes D3DFMT_A8R8G8B8
			if(spoutsender.CreateSender(SenderName, m_Width, m_Height)) {
				bInitialized = true;
			}
		}
		else if(m_Width != desc.Width || m_Height != desc.Height) {
			// Initialized but has the texture changed size ?
			m_Width = desc.Width;
			m_Height = desc.Height;
			// Update the sender	
			spoutsender.UpdateSender(SenderName, m_Width, m_Height);
		}
		else if(bSpoutOut) { // Initialized and plugin has started

			// Copy from video memory to system memory
			hr = d3d_device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &source_surface, NULL);
			if(SUCCEEDED(hr)) {
				// Get the Virtual DJ texture Surface
				hr = dxTexture->GetSurfaceLevel(0, &texture_surface);
				if(SUCCEEDED(hr)) {
					// Get the rendertarget data into system memory
					hr = d3d_device->GetRenderTargetData(texture_surface, source_surface);	
					if(SUCCEEDED(hr)) {
						// Lock the source surface using some flags for optimization
						hr = source_surface->LockRect(&d3dlr, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY);
						if(SUCCEEDED(hr)) {
							// Pass the pixels to spout
							spoutsender.SendImage((unsigned char *)d3dlr.pBits, desc.Width, desc.Height, GL_BGRA_EXT);
							source_surface->UnlockRect();
						}
					}
				}
			}
			if(texture_surface) texture_surface->Release();
			if(source_surface) source_surface->Release();
			texture_surface = NULL;
			source_surface = NULL;

		}
	}

	DrawDeck(); // Draw the image coming in

	return S_OK;

}