Exemplo n.º 1
0
CWBOOL cwSprite::init()
{
	if (!cwRenderNode2D::init()) return CWFALSE;
	if (!buildVertexBuffer()) return CWFALSE;

	return CWTRUE;
}
ParticleExplosionNode2::ParticleExplosionNode2(QVector3D pos,Primitive *p,std::string name)
    :SceneGraph(p,name)
{
    this->emitterPos=pos;
    nParticles=20;
    for(int i=0;i<nParticles;i++){
        Particle temp=Particle();
        particles.push_back(temp);
    }
    //erzeugt ale Partikel
    emitParticles();
    buildVertexBuffer();

    std::string fileName = ":/img/sprites/smoke.png";
    QImage tex;
    QString fileQT = QString(fileName.c_str());

    tex.load(fileQT);
    tex = QGLWidget::convertToGLFormat(tex);

    glGenTextures(1, &sprite);
    glBindTexture(GL_TEXTURE_2D, sprite);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glBindTexture(GL_TEXTURE_2D, 0);

	glGenBuffers(1, &alphaBufferObject);
	glGenBuffers(1, &texCoordsBufferObject);
	glGenBuffers(1, &vertexBufferObject);
}
Exemplo n.º 3
0
DiffuseCubeDemo::DiffuseCubeDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	mGfxStats = new GfxStats();

	mCameraRadius    = 10.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 5.0f;

	mLightVecW    = D3DXVECTOR3(-0.5, 0.75f, -2.0f);
	D3DXVec3Normalize(&mLightVecW, &mLightVecW);
	mDiffuseMtrl  = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
	mDiffuseLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	D3DXMatrixIdentity(&mWorld);

	buildVertexBuffer();
	buildIndexBuffer();
	buildFX();

	onResetDevice();

	InitAllVertexDeclarations();
}
Exemplo n.º 4
0
CWBOOL cwSprite::init(const std::string& strFile)
{
	if (!cwRenderNode2D::init()) return CWFALSE;
	if (!loadTexture(strFile)) return CWFALSE;
	if (!buildVertexBuffer()) return CWFALSE;

	return CWTRUE;
}
Exemplo n.º 5
0
void CubeDemo::init(HWND* hWnd) {
    D3DRenderer::init(hWnd);

    mCameraRadius    = 10.0f;
    mCameraRotationY = 1.2 * D3DX_PI;
    mCameraHeight    = 5.0f;

    buildVertexBuffer();
    buildIndexBuffer();

    buildProjMtx();

    initAllVertexDeclarations();
}
Exemplo n.º 6
0
CubeDemo::CubeDemo(HINSTANCE hInstance, std::wstring winCaption)
	: D3DApp(hInstance, winCaption)
{
	mGfxStats = new GfxStats();

	mCameraRadius    = 10.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 5.0f;

	buildVertexBuffer();
	buildIndexBuffer();

	onResetDevice();

	InitAllVertexDeclarations();
}
Exemplo n.º 7
0
/*
	Name		ParticleSystem::initialise
	Syntax		ParticleSystem::initialise(ID3D10Device* device, 
										   ID3D10ShaderResourceView* texArrayRV, 
										   UINT maxParticles)
	Param		ID3D10Device* device - The D3D device
	Param		ID3D10ShaderResourceView* texArrayRV - Handle to textures used
				by the particle system
	Param		UINT maxParticles - The maximum number of particles this system
				should emit
	Brief		Initialises the particle system
*/
void ParticleSystem::initialise(ID3D10Device* device, 
								ID3D10ShaderResourceView* texArrayRV,

								UINT maxParticles)
{
	d3dDevice_ = device;

	particleShader_ = new ParticleShader;
	particleShader_->initialise(particle_);

	maxParticles_ = maxParticles;

	texArrayRV_  = texArrayRV;
	randomTexRV_ = createRandomTexture(); 

	buildVertexBuffer();
}
void ParticleExplosionNode2::updateParticles(float deltaTime){

    for ( unsigned int i = 0; i < particles.size(); ++i )
       {
           Particle& particle = particles[i];

           particle.time += deltaTime;
           if ( particle.time > particle.lifeTime)
           {
                   emitParticle(particle);
           }

           float lifeRatio = particle.time/ particle.lifeTime;
           particle.velocity+= ( force * 0.01);
           particle.pos += ( particle.velocity * 0.1);
           particle.alpha=  lifeRatio ;
           particle.rotate= lerp(0.0f, 720.0f, lifeRatio );
           particle.size = lerp( 1.0f, 0.0f, lifeRatio );
       }

       buildVertexBuffer();
}
Exemplo n.º 9
0
//
// Vulkan initialization.
//
VkBool32 Example::init(const vkts::IUpdateThreadContext& updateContext)
{
	if (!updateContext.isDisplayAttached(displayIndex))
	{
		return VK_FALSE;
	}

	if (!updateContext.isWindowAttached(windowIndex))
	{
		return VK_FALSE;
	}

	windowDimension = updateContext.getWindowDimension(windowIndex);

	//

	VkResult result;

	//

	if (!vkts::wsiGatherNeededInstanceExtensions())
	{
		vkts::logPrint(VKTS_LOG_WARNING, "Example: Could not gather instance extensions.");

		return VK_TRUE;
	}

	instance = vkts::instanceCreate(VKTS_EXAMPLE_NAME, VK_MAKE_VERSION(1, 0, 0), VK_MAKE_VERSION(1, 0, 0), 0, 0, nullptr, vkts::extensionGetNeededInstanceExtensionCount(), vkts::extensionGetNeededInstanceExtensionNames());

	if (!instance.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not create instance.");

		return VK_FALSE;
	}

	if (!vkts::wsiInitInstanceExtensions(instance->getInstance()))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not initialize instance extension.");

		return VK_FALSE;
	}

	physicalDevice = vkts::physicalDeviceCreate(instance->getInstance(), 0);

	if (!physicalDevice.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not get physical device.");

		return VK_FALSE;
	}


	if (!vkts::wsiGatherNeededDeviceExtensions(physicalDevice->getPhysicalDevice()))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not gather device extension.");

		return VK_FALSE;
	}

	//

	surface = vkts::wsiSurfaceCreate(instance->getInstance(), updateContext.getNativeDisplay(displayIndex), updateContext.getNativeWindow(windowIndex));

	if (!surface.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not create surface.");

		return VK_FALSE;
	}

	//

	std::vector<VkBool32> supportFilter;

	result = vkts::wsiGetPhysicalDeviceSurfaceSupport(physicalDevice->getPhysicalDevice(), surface->getSurface(), (uint32_t) physicalDevice->getAllQueueFamilyProperties().size(), supportFilter);

	if (result != VK_SUCCESS || supportFilter.size() == 0)
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not get physical device surface support.");

		return VK_FALSE;
	}

	//

	uint32_t queueFamilyIndex;

	if (!vkts::queueGetFamilyIndex(physicalDevice->getAllQueueFamilyProperties(), VK_QUEUE_GRAPHICS_BIT, 0, &supportFilter, queueFamilyIndex))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not find queue family index.");

		return VK_FALSE;
	}

	//

	float queuePriorities[1] = {0.0f};

	VkDeviceQueueCreateInfo deviceQueueCreateInfo;

	memset(&deviceQueueCreateInfo, 0, sizeof(VkDeviceQueueCreateInfo));

	deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;

	deviceQueueCreateInfo.flags = 0;
	deviceQueueCreateInfo.queueFamilyIndex = 0;
	deviceQueueCreateInfo.queueCount = 1;
	deviceQueueCreateInfo.pQueuePriorities = queuePriorities;

	device = vkts::deviceCreate(physicalDevice->getPhysicalDevice(), 0, 1, &deviceQueueCreateInfo, 0, nullptr, vkts::extensionGetNeededDeviceExtensionCount(), vkts::extensionGetNeededDeviceExtensionNames(), nullptr);

	if (!device.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Test: Could not create device.");

		return VK_FALSE;
	}

	if (!vkts::wsiInitDeviceExtensions(device->getDevice()))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not initialize device extension.");

		return VK_FALSE;
	}

	//

	queue = vkts::queueGet(device->getDevice(), queueFamilyIndex, 0);

	if (!queue.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not get device queue.");

		return VK_FALSE;
	}

	//

	commandPool = vkts::commandPoolCreate(device->getDevice(), 0, queue->getQueueFamilyIndex());

	if (!commandPool.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not get command pool.");

		return VK_FALSE;
	}

	//

	imageAcquiredSemaphore = vkts::semaphoreCreate(device->getDevice(), 0);

	if (!imageAcquiredSemaphore.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not create semaphore.");

		return VK_FALSE;
	}

    renderingCompleteSemaphore = vkts::semaphoreCreate(device->getDevice(), 0);

    if (!renderingCompleteSemaphore.get())
    {
        vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not create semaphore.");

        return VK_FALSE;
    }

	//

	if (!buildVertexBuffer())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not build vertex buffer.");

		return VK_FALSE;
	}

	if (!buildShader())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not build shader.");

		return VK_FALSE;
	}

	if (!buildPipelineCache())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not build pipeline cache.");

		return VK_FALSE;
	}

	if (!buildPipelineLayout())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not build pipeline layout.");

		return VK_FALSE;
	}

	//

	if (!buildResources(updateContext))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not build resources.");

		return VK_FALSE;
	}

	return VK_TRUE;
}
Exemplo n.º 10
0
Mesh::Mesh(const std::string& a_Filepath, ID3D11Device* a_Device)
{
	loadMeshdata(a_Filepath);
	buildVertexBuffer(a_Device);
	buildIndexBuffer(a_Device);
}