- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将纹理与 LWJGL 一起使用,结果发现 RBG-png 有点倾斜。例子: Original picture/Texture
加载代码是 lwjgl wiki Space Invaders 示例的 98%。纹理.java:
public int target, textureID, height, width, texWidth, texHeight;
private float widthRatio, heightRatio;
public Texture(int target, int textureID) {
this.target = target;
this.textureID = textureID;
}
public void bind() {
GL11.glBindTexture(target, textureID);
}
public void setWidth(int width) {
this.width = width;
setWidth();
}
public void setHeight(int height) {
this.height = height;
setHeight();
}
public int getImageWidth() {
return width;
}
public int getImageHeight() {
return height;
}
public float getWidth() {
return widthRatio;
}
public float getHeight() {
return heightRatio;
}
public void setTextureWidth(int texWidth) {
this.texWidth = texWidth;
setWidth();
}
public void setTextureHeight(int texHeight) {
this.texHeight = texHeight;
setHeight();
}
private void setWidth() {
if (texWidth != 0)
widthRatio = ((float) width) / texWidth;
}
private void setHeight() {
if (texHeight != 0)
heightRatio = ((float) height) / texHeight;
}
TextureLoader.java:
private static HashMap<String, Texture> table = new HashMap<String, Texture>();
private static ColorModel glAlphaColorModel, glColorModel;
private static IntBuffer textureIDBuffer = BufferUtils.createIntBuffer(1);
static {
glAlphaColorModel = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8,
8, 8 }, true, false, ComponentColorModel.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
glColorModel = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8,
8, 0 }, false, false, ComponentColorModel.OPAQUE,
DataBuffer.TYPE_BYTE);
}
private static int createTextureID() {
GL11.glGenTextures(textureIDBuffer);
return textureIDBuffer.get(0);
}
public static Texture getTexture(String name, BufferedImage image)
throws IOException {
Texture tex = table.get(name);
if (tex != null)
return tex;
tex = getTexture(image, GL11.GL_TEXTURE_2D, GL11.GL_RGBA,
GL11.GL_LINEAR, GL11.GL_LINEAR);
table.put(name, tex);
return tex;
}
public static Texture getTexture(BufferedImage image, int target,
int dstPixelFormat, int minFilter, int magFilter)
throws IOException {
int srcPixelFormat;
int textureID = createTextureID();
Texture texture = new Texture(target, textureID);
GL11.glBindTexture(target, textureID);
texture.setWidth(image.getWidth());
texture.setHeight(image.getHeight());
if (image.getColorModel().hasAlpha())
srcPixelFormat = GL11.GL_RGBA;
else
srcPixelFormat = GL11.GL_RGB;
ByteBuffer textureBuffer = convertImageData(image, texture);
if (target == GL11.GL_TEXTURE_2D) {
GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
}
GL11.glTexImage2D(target, 0, dstPixelFormat, image.getWidth(),
image.getHeight(), 0, srcPixelFormat,
GL11.GL_UNSIGNED_BYTE, textureBuffer);
return texture;
}
private static ByteBuffer convertImageData(BufferedImage bufferedImage,
Texture texture) {
ByteBuffer imageBuffer;
WritableRaster raster;
BufferedImage texImage;
int texWidth = bufferedImage.getWidth();
int texHeight = bufferedImage.getHeight();
texture.setTextureHeight(texHeight);
texture.setTextureWidth(texWidth);
if (bufferedImage.getColorModel().hasAlpha()) {
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
texWidth, texHeight, 4, null);
texImage = new BufferedImage(glAlphaColorModel, raster, false,
new Hashtable());
} else {
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
texWidth, texHeight, 3, null);
texImage = new BufferedImage(glColorModel, raster, false,
new Hashtable());
}
Graphics g = texImage.getGraphics();
g.setColor(new Color(0f, 0f, 0f, 0f));
g.fillRect(0, 0, texWidth, texHeight);
g.drawImage(bufferedImage, 0, 0, null);
// texImage is NOT skewed at this point
byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer())
.getData();
imageBuffer = ByteBuffer.allocateDirect(data.length);
imageBuffer.order(ByteOrder.nativeOrder());
imageBuffer.put(data, 0, data.length);
imageBuffer.flip();
return imageBuffer;
}
最佳答案
我知道这是一个老问题,但我自己刚才也遇到了这个问题。假设您已经自己解决了这个问题,希望其他人也会受益。
纹理倾斜和变色的原因是它与您的 UNPACK_ALIGNMENT
没有正确对齐。据我了解,每行中的字节数必须是 UNPACK_ALIGNMENT
设置的倍数(默认为 4)。
对于 4 分量格式,这不是问题,因为每个像素由 4 个字节组成,因此任何尺寸的图像都会正确对齐。但对于其他格式,数据会被填充以保持正确对齐,这会导致这样的问题。
您可以更改图像的大小以使其正确对齐 ((width * formatComponents) % 4 == 0)
、将格式更改为 4 分量格式,或者更改UNPACK_ALIGNMENT
到不会使用以下方式填充图像的内容:
glPixelStore(GL_UNPACK_ALIGNMENT, 对齐);//对齐方式必须为 1、2、4 或 8
。
http://www.opengl.org/wiki/Common_Mistakes#Texture_upload_and_pixel_reads
关于java - LWJGL 倾斜纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14203226/
我是初学者,我正在做一些练习来熟悉 CALayer ... 我只是想知道如何“倾斜”(或倾斜)CALayer 45° 角? 谢谢。 最佳答案 CALayers 有一个属性 affineTransfor
无法理解如何制作this trick或 this与CSS。我的意思是标题和标志。这条线不直。它们是倾斜的/倾斜的边界。能否请您举个例子或只是举例说明这是可行的? 最佳答案 看看https://jsfi
如何倾斜图像?例如,每个角都有一个 CGPoint,其坐标为 - p1、p2、p3、p4。然后,我需要设置 - p4.x+=50,p4.y+=30。因此这个角 (p4) 应该在 2D 透视中拉伸(st
我想弄清楚如何通过仅使用 css 来实现元素底部的跟随边框,并使其尽可能对跨浏览器友好 示例代码,带有标准边框 .object { width: 200px; height: 45p
我正在尝试使用 CSS transform 来倾斜 Bootstrap 导航 li,我可以做到这一点,但是当我尝试扭转内部链接上的倾斜时,li 倾斜也会反转回来。我不知道为什么。我试着做这里接受的答案
这个问题在这里已经有了答案: CSS: Set a background color which is 50% of the width of the window (14 个答案) 关闭 7 年前
我已经创建了一个预定的 div 来与我的导航栏一起使用,但是它弄乱了网站的其余格式。导航栏位于右上角,倾斜的 div 位于其下方,但它弄乱了网页上的所有其他内容。我一直在尝试一切都无济于事。 http
你好,我想像这里的附图一样对步骤菜单进行风格化。我该如何风格化这个?主要问题是菜单右侧的边框。 检查我的 JSFiddle URL https://jsfiddle.net/hcx1pv8x/ , 不
我正在尝试使用 HTML5 在 javascript 中倾斜 svg 元素,例如: 中的矩形元素是倾斜的,但 rect 元素也向右移动(不需要),我尝试手动设置位置使用 transform
目前我对应该倾斜的容器使用clip-path。 .box { height: 150px; line-height: 150px; text-align: center; backgr
我有一个相机从上方指向禅宗花园。然而,相机固定在侧面而不是直接在板的上方。结果,图像看起来像这样(注意矩形的倾斜形状): 有没有办法处理图像,使沙子区域看起来或多或少像一个完美的正方形? cap =
我正在尝试使用倾斜 350 度的 UIScrollview,我首先想到的是使用变换属性,滚动上的倾斜起作用了,但现在滚动上的所有内容看起来都不对,当我谈论所有内容时,我指的是位置和这个卷轴的所有 ch
我需要将我的应用程序升级到 Rails 3.2.16,当时我做了 bundle update rails它给了我以下错误。 Bundler could not find compatible vers
我正在尝试运行 rake db:migrate在本地,但我收到以下错误: Gem::LoadError: You have already activated rake 10.2.2, but you
很难用语言表达我想要完成的事情,所以请查看这张照片作为示例: 如您所见,我希望创建一个带有图案背景的倾斜 div(简单),但另一部分,即倾斜被半遮住的部分,也必须有背景图像。我想到了很多不同的想法,并
假设,我想将两个二维数组添加到第三个二维数组中。 我正在使用以下代码: cudaMallocPitch((void**)&device_a, &pitch, 2*sizeof(int),2); cud
很难用语言表达我想要完成的事情,所以请查看这张照片作为示例: 如您所见,我希望创建一个带有图案背景的倾斜 div(简单),但另一部分,即倾斜被半遮住的部分,也必须有背景图像。我想到了很多不同的想法,并
我刚刚遇到了这种附加字符串的变体,其中包含存储在变量中的值,这是我以前从未见过的。谁能帮我解释一下这是怎么回事? 这是我遇到的情况: var fruit = "banana"; $main = $('
假设,我想将两个二维数组添加到第三个二维数组中。 我正在使用以下代码: cudaMallocPitch((void**)&device_a, &pitch, 2*sizeof(int),2); cud
我正在尝试分析在 Windows 上运行的 Java UI 应用程序的 CPU 使用率。我将它连接到 VisualVM,但看起来 CPU 使用率最高的是 sum.rmi.transport.tcp.T
我是一名优秀的程序员,十分优秀!