我想从某个位图拉伸或平铺opengl对象。我使用位图的一部分的图像。 但我的戒指和中间纹理与图像的平均颜色。如果我改变图像颜色变化,但图片没有显示。
和我的完整代码
// ..in init///
gl.glEnable(GL10.GL_TEXTURE_2D);
textures = new int[3];
bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.pizzaf);
bitmap = Bitmap.createBitmap( bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), null, true);
bitmap1 = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.pizslice);
bitmap1 = Bitmap.createBitmap( bitmap1, 0, 0, bitmap1.getWidth(),
bitmap1.getHeight(), null, true);
// Tell OpenGL to generate textures.
gl.glTexParameterf(GL10.GL_TEXTURE_2D,
GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
// gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
// GL10.GL_LINEAR);
// gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
// GL10.GL_LINEAR);
gl.glGenTextures(1, textures, 0);
}
并绘制函数
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap1, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
GLUT.glutSolidTorus(gl,0.175f, 0.95f, 12, 48);
gl.glTranslatef(0,0, 0.2f);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
GLUT.glutSolidCone(gl, 1,0.01f, 12, 48);
gl.glTranslatef(0,0, -0.4f);
gl.glRotatef (180.0f, 1.0f, 0.0f, 0.0f);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap1, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
GLUT.glutSolidCone(gl, 1,0.01f, 12, 48);
请帮助任何人。我想制作一个3d披萨
答案 0 :(得分:3)
您的代码中存在3个问题:
根据此方案始终加载纹理:
GLuint texture_object_name;
glGenTextures(1,
&texture_object_name); // you can create texture object names in batches
glBindTexture(GL_TEXTURE_2D, // may differ, depending on texture target (i.e. kind of texture)
texture_object_name);
glPixelStorei(GL_UNPACK_ALIGNMENT, …); // </ depends on data format
glPixelStorei(GL_UNPACK_ROW_LENGTH, …); // <|
glPixelStorei(GL_UNPACK_SKIP_PIXELS, …); // <|
glPixelStorei(GL_UNPACK_SKIP_ROWS, …); // <|
glTexImage2D(GL_TEXTURE_2D, // again the target, depends on the kind of texture creates
0, // mipmap level
GL_RGBA, // internal format, GL_RGBA is one possibility, there are others
width, height, border, // border is usually 0
GL_BGRA, // format of the data input
GL_UNSIGNED_INT_8_8_8_8, // type of the data input -- those must match the data
texture_data );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, …); // mipmapping on/off and other settings
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, …); // you should really set those
修复(1)后,您可以修复(2)。要在渲染时切换纹理,只需调用
即可glBindTexture(GL_TEXTURE_2D, texture_object_name);
在后续的绘图调用中使用它。
(3)通过自己定义几何图形来修复,提供适当的纹理坐标。