0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

XImageのイメージをテクスチャに取り込む

Last updated at Posted at 2013-08-16

そんな大層なものじゃないけどちょっとした処理の流れ。

	glBindTexture(GL_TEXTURE_2D, tID);
	glPixelStorei(GL_PACK_ALIGNMENT, 4);
	glTexImage2D(
		GL_TEXTURE_2D, 0, GL_RGB, w, h, 0,
		GL_BGRA, GL_UNSIGNED_BYTE, (*wImage).data);

こんな感じにテクスチャをbindして、アラインを指定して(GL_UNPACK_ALIGNMENT, 1でもおk)、格納先フォーマットをGL_RGB、取り込むフォーマットをGL_BGRAにしとくというだけの話。ZPixmapのXImageは画面が24bitsモードだと32bitsパックドなのでGL_BGRAにしてアルファ付きにしとく。あと、XImageでは並びがRGBじゃなくてBGRAらしい。

ちなみに、私ゃテクスチャのバインドを忘れてしばらく混乱してたよ。

それと、これはサイズが2のn乗ってのは考慮してない。考慮するなら...

	const int w(1024); //試験用の値なので固定値になってる。実際にはサイズ以上の2^n値を計算する
	const int h(1024); //同上
	wImage = XCreateImage(
		xDisplay,
		DefaultVisual(xDisplay,0),
		DefaultDepth(xDisplay,0),
		ZPixmap,0,0,w,h,32,0);
	(*wImage).data = (char*)malloc(w * h * 4);
	assert(wImage);
	XGetSubImage(
		xDisplay,
		wID,
		0, 0,
		width, height,
		AllPlanes,
		ZPixmap,
		wImage,
		0, 0);

...みたいに一旦XImage構造を作ってからXGetSubImageで部分書き換えするといい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?