简体   繁体   English

Android OpenGL着色器-以1:1大小显示图像

[英]Android OpenGL shader - show image at 1:1 size

Hi I have a 512x512 texture that I would like to display within my GlSurfaceview at a 100% scale at a 1:1 pixel for pixel view. 嗨,我有一个512x512纹理,我想以100%的比例在1:1像素的像素视图中显示在GlSurfaceview中。 I have having troubles achieving this and require some assistance. 我在实现此目标方面遇到困难,需要一些帮助。 Every combination of settings in OnSurfaceChanged and onDrawFrame result in a scaled image. OnSurfaceChanged和onDrawFrame中设置的每种组合都会生成缩放的图像。 Can someone pls direct me to an example where this is possible. 有人可以引导我举一个可能的例子吗?

private float[] mProjectionMatrix = new float[16];

// where mWidth and mHeight are set to 512
public void onSurfaceChanged(GL10 gl, int mWidth, int mHeight) {
 GLES20.glViewport(0, 0, mWidth, mHeight); 
 float left = -1.0f /(1/ScreenRatio );
 float right = 1.0f /(1/ScreenRatio );
 float bottom = -1.0f ;
 float top = 1.0f   ;
 final float near = 1.0f;
 final float far = 10.0f;
 Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
}

@Override
public void onDrawFrame(GL10 glUnused ) {
 ....stuff here 
 Matrix.setIdentityM(mModelMatrix, 0); 
 Matrix.translateM(mModelMatrix, 0, 0, 0, 1);
 Matrix.rotateM(mModelMatrix, 0, 0.0f, 1.0f, 1.0f, 0.0f); 
 drawCube(); 
}  

many thanks, 非常感谢,

There's various options. 有多种选择。 The simplest IMHO is to not apply any view/projection transformations at all. 最简单的恕我直言是根本不应用任何视图/投影转换。 Then draw a textured quad with a range of (-1.0, 1.0) for both the x- and y-coordinates. 然后为x和y坐标绘制一个纹理范围为(-1.0,1.0)的四边形。 That would get your texture to fill the entire view. 那将使您的纹理充满整个视图。 Since you want it displayed in a 512x512 part of the view, you can set the viewport to cover only that area: 由于您希望它显示在视图的512x512部分中,因此可以将视口设置为仅覆盖该区域:

glViewport(0, 0, 512, 512);

Another possibility is that you reduce the range of your input coordinates to map to a 512x512 area of the screen. 另一种可能性是您减小了输入坐标的范围以映射到屏幕的512x512区域。 Or scale the coordinates in the vertex shader. 或在顶点着色器中缩放坐标。

You didn't specify what version of OpenGL ES you use. 您没有指定要使用的OpenGL ES版本。 In ES 3.0, you could also use glBlitFramebuffer() to copy the texture to your view. 在ES 3.0中,还可以使用glBlitFramebuffer()将纹理复制到视图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM