本文整理汇总了C++中LTexture::getPitch方法的典型用法代码示例。如果您正苦于以下问题:C++ LTexture::getPitch方法的具体用法?C++ LTexture::getPitch怎么用?C++ LTexture::getPitch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LTexture
的用法示例。
在下文中一共展示了LTexture::getPitch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadMedia
bool loadMedia() {
//Loading success flag
bool success = true;
//Load foo' texture
if( !gFooTexture.loadFromFile( "40_texture_manipulation/foo.png" ) ) {
printf( "Failed to load corner texture!\n" );
success = false;
} else {
//Lock texture
if( !gFooTexture.lockTexture() ) {
printf( "Unable to lock Foo' texture!\n" );
}
//Manual color key
else {
//Get pixel data
Uint32* pixels = (Uint32*)gFooTexture.getPixels();
int pixelCount = ( gFooTexture.getPitch() / 4 ) * gFooTexture.getHeight();
//Map colors
Uint32 colorKey = SDL_MapRGB( SDL_GetWindowSurface( gWindow )->format, 0, 0xFF, 0xFF );
Uint32 transparent = SDL_MapRGBA( SDL_GetWindowSurface( gWindow )->format, 0xFF, 0xFF, 0xFF, 0x00 );
//Color key pixels
for( int i = 0; i < pixelCount; ++i ) {
if( pixels[ i ] == colorKey ) {
pixels[ i ] = transparent;
}
}
//Unlock texture
gFooTexture.unlockTexture();
}
}
return success;
}
示例2: loadLetters
bool loadLetters()
{
bool success = true;
if (!gFontTexture.loadFromFile("font.png")) {
printf("Failed to load corner texture!\n");
success = false;
}
else {
if (!gFontTexture.lockTexture()) {
printf("Unable to lock font texture!\n");
}
else {
Uint32* pixels = (Uint32*)gFontTexture.getPixels();
int pixelCount = (gFontTexture.getPitch() / 4) * gFontTexture.getHeight();
int width = gFontTexture.getWidth();
int height = gFontTexture.getHeight();
std::vector<std::vector<Uint32>> pixelGrid;
pixelGrid.resize(height, std::vector<Uint32>(width));
Uint32 white = SDL_MapRGB(SDL_GetWindowSurface(gWindow)->format, 255, 255, 255);
Uint32 cyan = SDL_MapRGB(SDL_GetWindowSurface(gWindow)->format, 0, 255, 255);
int k = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixelGrid[i][j] = pixels[k];
k++;
}
}
std::vector<SDL_Rect> boxes;
int current = 0;
int rightEdge = 0;
int leftEdge = 0;
int state = 1;
int rowCount = height / LINE_HEIGHT;
printf("%d\n", rowCount);
for (int i = 0; i < rowCount; i++) {
for (int j = 0; j < width; j++) {
printf("%d %d\n", i, j);
int value = hasBlack(pixelGrid, i, j, white, cyan);
if (value == 1) {
if (state == 1) {
leftEdge = j;
state = 2;
}
if (state == 2) {
rightEdge = j;
}
}
if (value == 2) {
SDL_Rect currentBox;
currentBox.x = leftEdge;
currentBox.y = i * LINE_HEIGHT;
currentBox.w = rightEdge - leftEdge;
currentBox.h = LINE_HEIGHT - 1;
if (currentBox.w < 10) {
currentBox.w = 10;
}
printf("%d %d %d %d\n", currentBox.x, currentBox.y, currentBox.w, currentBox.h);
boxes.push_back(currentBox);
state = 1;
}
}
}
convert(boxes);
gFontTexture.unlockTexture();
}
}
return success;
}