当前位置: 首页>>代码示例>>C++>>正文


C++ VisualGraphics::yPixelToCoord方法代码示例

本文整理汇总了C++中VisualGraphics::yPixelToCoord方法的典型用法代码示例。如果您正苦于以下问题:C++ VisualGraphics::yPixelToCoord方法的具体用法?C++ VisualGraphics::yPixelToCoord怎么用?C++ VisualGraphics::yPixelToCoord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VisualGraphics的用法示例。


在下文中一共展示了VisualGraphics::yPixelToCoord方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createReadPixels

PixelColor* VisualTextureContainer::createReadPixels(const uint16 format, const uint16 type) {
	
	PixelColor* pixels = NULL;
	PixelColor* prevPixels = NULL;
	
	char errStr[512];
	
	double scaleFactor = 1.0;
	
	uint8 numberOfBytesPerChannel = 0;
	uint8 numberOfChannels = 0; // channel == color resp. alpha channel
	uint8 numberOfBytesPerPixel = 0;
	uint32 numberOfBytesPerRow = 0;
	if ((format == kGL_RGBA) || (format == kGL_BGRA)) {
		numberOfChannels = 4;
	} else {
		sprintf(errStr, "unknown format %d in file: %s (line: %d) [%s])", format, __FILE__, __LINE__, __FUNCTION__);
		writeLog(errStr);
		return pixels;
	}
	
	if ((type == kGL_UNSIGNED_INT_8_8_8_8_REV) || (type == kGL_UNSIGNED_INT_8_8_8_8) || (type == kGL_UNSIGNED_BYTE)) {
		numberOfBytesPerChannel = 1; // // 1 byte (== 8 bits) per color/channel
	} else {
		sprintf(errStr, "unknown type %d in file: %s (line: %d) [%s])", type, __FILE__, __LINE__, __FUNCTION__);
		writeLog(errStr);
		return pixels;
	}
	
	numberOfBytesPerPixel = numberOfBytesPerChannel * numberOfChannels;
	numberOfBytesPerRow = numberOfBytesPerPixel * this->textureRect.width;
	
	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
	
	Coord coord;
	VisualCamera aCamera;
	aCamera.setOrthographicProjection();
	coord.x = aCamera.getMaxLeftCoord() * scaleFactor;
	coord.y = (aCamera.getMaxBottomCoord() + theVisualGraphics->yPixelToCoord(this->textureRect.height, aCamera)) * scaleFactor;
	coord.z = aCamera.getMaxNearPos();
	VertexChain aVertexChain;
	TexCoord texCoord;
	texCoord.s = 0.0;
	texCoord.t = this->getTextureLogicalHeight();
	VisualVertex* topLeftFrontVertex = new VisualVertex(coord, texCoord, white);
	aVertexChain.push_back(topLeftFrontVertex);
	
	coord.x = aCamera.getMaxLeftCoord() * scaleFactor;
	coord.y = aCamera.getMaxBottomCoord() * scaleFactor;
	coord.z = aCamera.getMaxNearPos();
	texCoord.s = 0.0;
	texCoord.t = 0.0;
	VisualVertex* bottomLeftFrontVertex = new VisualVertex(coord, texCoord, white);
	aVertexChain.push_back(bottomLeftFrontVertex);
	
	coord.x = (aCamera.getMaxLeftCoord() + theVisualGraphics->xPixelToCoord(this->textureRect.width, aCamera)) * scaleFactor;
	coord.y = aCamera.getMaxBottomCoord() * scaleFactor;
	coord.z = aCamera.getMaxNearPos();
	texCoord.s = this->getTextureLogicalWidth();
	texCoord.t = 0.0;
	VisualVertex* bottomRightFrontVertex = new VisualVertex(coord, texCoord, white);
	aVertexChain.push_back(bottomRightFrontVertex);
	
	coord.x = (aCamera.getMaxLeftCoord() + theVisualGraphics->xPixelToCoord(this->textureRect.width, aCamera)) * scaleFactor;
	coord.y = (aCamera.getMaxBottomCoord() + theVisualGraphics->yPixelToCoord(this->textureRect.height, aCamera)) * scaleFactor;
	coord.z = aCamera.getMaxNearPos();
	texCoord.s = this->getTextureLogicalWidth();
	texCoord.t = this->getTextureLogicalHeight();
	VisualVertex* topRightFrontVertex = new VisualVertex(coord, texCoord, white);
	aVertexChain.push_back(topRightFrontVertex);
	
	// read previous pixels
	if ((format == kGL_RGBA) || (format == kGL_BGRA)) {
		prevPixels = (uint32*)calloc((numberOfBytesPerRow / numberOfBytesPerPixel) * this->textureRect.height, numberOfBytesPerPixel);
	}
	theVisualGraphics->readPixels(aCamera.getMaxLeftCoord(), aCamera.getMaxBottomCoord(), this->textureRect.width, this->textureRect.height, &prevPixels, format, type, aCamera);
	
	// draw current texture
	theVisualGraphics->drawTexture(this->textureName, &aVertexChain, this->getUseRectExtension(), kReplace);
	
	// read pixels of current texture
	if ((format == kGL_RGBA) || (format == kGL_BGRA)) {
		pixels = (uint32*)calloc((numberOfBytesPerRow / numberOfBytesPerPixel) * this->textureRect.height, numberOfBytesPerPixel);
	}
	theVisualGraphics->readPixels(aCamera.getMaxLeftCoord(), aCamera.getMaxBottomCoord(), this->textureRect.width, this->textureRect.height, &pixels, format, type, aCamera);
	
	// restore previous pixels
	theVisualGraphics->drawPixels(&prevPixels, aCamera.getMaxLeftCoord(), aCamera.getMaxBottomCoord(), this->textureRect.width, this->textureRect.height, format, type);
	
	for (VertexChainIterator chainIt = aVertexChain.begin(); chainIt != aVertexChain.end(); chainIt++) {
		delete *chainIt;
		*chainIt = NULL;
	}
	aVertexChain.clear();
	
	free(prevPixels);
	
	return pixels;
}
开发者ID:LupusDei,项目名称:8LU-DSP,代码行数:99,代码来源:VisualTextureContainer.cpp


注:本文中的VisualGraphics::yPixelToCoord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。