http://www.play21.jp/board/formz.cgi?ac ... &rln=63427
お礼が遅くなってしまいすみませんでした。
int型でのスクロールは問題なく見えるのですがfloat型ですとスクロールがおかしいです。
URL一番↓の様に修正してみたのですがやはりカクカクしてしまいます。
下記のソースではスクロールしなければいけない所までくるとカクカクになりスクロール速度が落ちている様に見えてしまいます。
何とか修正したいのですがうまくいきません。
背景の画像サイズは1024×512です。
画面サイズは320×480です。
DrawTexture関数は指定した座標の中心点に描画します。
#define SCROLL_SPEED 0.5f
// init
scBack = 0;
// loop
scBack += SCROLL_SPEED;
if( scBack >= 1024 ) scBack -= 1024;
// 描画処理
int copy_w = (scBack < 1024 - 320) ? 320 : 1024 - scBack;
int size = int(320-copy_w);
DrawTexture(160, 240, texBack, scBack, 0, 320, 480, 0xffffff, 255);
if (copy_w < 320){
DrawTexture( int(320-size/2), 240, texBack, 0, 0, size, 480, 0xffffff, 255);
//if( scBack == copy_w ) DrawTexture( int(320-size/2)+1, 240, texBack, 0, 0, size, 480, 0xffffff, 255);
//else DrawTexture( int(320-size/2), 240, texBack, 0, 0, size, 480, 0xffffff, 255);
}
void DrawTexture( int x, int y, Texture texture, int texStartX, int texStartY, int texSizeX, int texSizeY, int color, int alpha ){
int r = color >> 16;
int g = (color >> 8) & 0xff;
int b = color & 0xff;
DrawTexture( x, y, texture, texStartX, texStartY, texSizeX, texSizeY, r, g, b, alpha );
}
void DrawTexture( int x, int y, Texture texture, int texStartX, int texStartY, int texSizeX, int texSizeY, int red, int green, int blue, int alpha ){
// テクスチャのサイズの半分の値を取得
int width = texture.imageSize.width;
int height = texture.imageSize.height;
int w = texSizeX / 2;
int h = texSizeY / 2;
// 読み込むテクスチャの領域を指定
float startX,startY,sizeX,sizeY;
// 開始位置
if( texStartX == 0 ) startX = 0.0f;
else startX = (float)texStartX / (float)width;
if( texStartY == 0 ) startY = 0.0f;
else startY = (float)texStartY / (float)height;
// 終了位置
if( texSizeX == 0 ) sizeX = 0.0f;
else sizeX = (float)texSizeX / (float)width;
if( texSizeY == 0 ) sizeY = 0.0f;
else sizeY = (float)texSizeY / (float)height;
//長方形を構成する四つの頂点の座標を決定します
const GLfloat squareVertices[/url] = {
x-w, y-h,
x+w, y-h,
x-w, y+h,
x+w, y+h,
};
//長方形を構成する四つの頂点の色を指定します
//ここではすべての頂点を同じ色にしています
const GLubyte squareColors[/url] = {
red, green, blue ,alpha,
red, green, blue ,alpha,
red, green, blue ,alpha,
red, green, blue ,alpha,
};
//元画像のどの範囲を描画に使うかを決定します
const GLfloat texCoords[/url] = {
startX, startY,
startX+sizeX, startY,
startX, startY+sizeY,
startX+sizeX, startY+sizeY,
};
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
//テクスチャ機能を有効にし、描画に使用するテクスチャを指定します
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture.texture);
//頂点座標と色、およびテクスチャの範囲を指定し、描画します
glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
//テクスチャ機能を無効にします
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
glDisable( GL_BLEND );
}