- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
原帖:
https://computergraphics.stackexchange.com/questions/4793/how-can-i-generate-mipmaps-manually
这是一个愚蠢的错误,我忘记设置所有纹理坐标 :P
OpenGL 相当难学。根据我对 mipmap 的理解,我可以手动设置每个 mipmap 级别,因此当我的纹理看起来更大或更小时,我可以更改要使用的图像。
我尝试了以下代码,但不管三角形的大小如何,它总是采用第一个 mipmap 级别。为什么?如果三角形更接近任何其他 mipmap 级别,为什么不接受它?
我真的很讨厌在我的问题中放一堆代码,因为我强制别人浪费时间分析代码而不是放最相关的代码片段,但我不知道问题出在哪里,我也别无选择。对不起:(
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
const GLchar* VERTEX_SHADER_SOURCE =
"#version 330 core \n"
"layout (location = 0) in vec2 position; \n"
"layout (location = 1) in vec2 myTexCoord; \n"
" \n"
"out vec2 TexCoord; \n"
" \n"
"void main() \n"
"{ \n"
" gl_Position = vec4(position,0.0f, 1.0f);\n"
" TexCoord = myTexCoord; \n"
"} \n";
const GLchar* FRAGMENT_SHADER_SOURCE =
"#version 330 core \n"
"in vec2 TexCoord; \n"
" \n"
"out vec4 color; \n"
" \n"
"uniform sampler2D ourTexture; \n"
" \n"
"void main() \n"
"{ \n"
" color = texture(ourTexture, TexCoord);\n"
"} \n";
int main()
{
//Change the value of size by 1,2,4,8,16,32,64,128 or 256 and see how the color of the triangle doesn't change. Why does it happen?
GLint size = 128;
//INIT STUFFS
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(size,size, "", nullptr, nullptr);
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
glewInit();
glViewport(0, 0,size,size);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
//Our image for the mipmap with odd level and green color
//The dimensions are 256 x 256 and is multiplied by 3 because I defined R,G and B colors
unsigned char imageArray[256*256*3];
for(int i = 0; i < 256*256*3; i++){
if((i+2)%3 == 0)
imageArray[i] = 255;
else
imageArray[i] = 0;
}
//Our image for the mipmap with pair level and red color
unsigned char imageArray2[256*256*3];
for(int i = 0; i < 256*256*3; i++){
if(i%3 == 0)
imageArray2[i] = 255;
else
imageArray2[i] = 0;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 8);
//All mipmap levels defined by hand
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);
glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);
glTexImage2D(GL_TEXTURE_2D, 4, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);
glTexImage2D(GL_TEXTURE_2D, 5, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);
glTexImage2D(GL_TEXTURE_2D, 6, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);
glTexImage2D(GL_TEXTURE_2D, 7, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);
glTexImage2D(GL_TEXTURE_2D, 8, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);
GLfloat vertices[] = {
-1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, //vertex coordinates
0.0f, 0.0f //Triangle's texture coordinates
};
//VAOs AND VBOs
GLuint VAO, VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat)*3*2));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
//SHADERS
GLuint program;
GLuint vertex, fragment;
vertex = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex, 1, &VERTEX_SHADER_SOURCE, NULL);
glCompileShader(vertex);
fragment = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment, 1, &FRAGMENT_SHADER_SOURCE, NULL);
glCompileShader(fragment);
program = glCreateProgram();
glAttachShader(program, vertex);
glAttachShader(program, fragment);
glLinkProgram(program);
glDeleteShader(vertex);
glDeleteShader(fragment);
glUseProgram(program);
//DRAWING OUR TRIANGLE
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0,3);
glfwSwapBuffers(window);
while (!glfwWindowShouldClose(window))
glfwPollEvents();
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glfwTerminate();
return 0;
}
最佳答案
您的 mipmap 设置看起来不错。但我看到您有这个:
GLfloat vertices[] = {
-1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, //vertex coordinates
0.0f, 0.0f //Triangle's texture coordinates
};
看起来您缺少 2 个其他顶点的 UV。另外,除非您想完全控制过滤技术等,否则我不会为手动生成 mipmap 而烦恼。
关于c++ - 手动生成 mipmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42596516/
对于 Metal ,如果对主纹理进行 mipmap 处理,是否还需要对多采样纹理进行 mipmap 处理?我阅读了苹果文档,但没有得到任何相关信息。 最佳答案 Mipmapping 适用于您将从中
是否有可能以某种方式为 mipmap 图标制作别名?例如,我们有一个名为 icon_app 的图标,但在我们的库中我们使用了 ic_launcher(应该是这样)。因此,对于可绘制对象,您可以使用 v
我正在制作一个基于 Maximum Mipmap structure 的高度图光线追踪器. 长话短说,我使用“最大过滤器”手动创建了一个带有 mipmap 级别的纹理。在 Debug模式下,程序运行良
我对使用这行代码自动生成的 mipmap 获得的质量不完全满意: glTexParameterf(GL10.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL10.G
我有一个 3D 纹理。每个纹素在 alpha channel 上包含一个透明度值。 我需要以这样一种方式生成我的 mipmap,它始终采用具有最大 alpha 值的纹素值。 换句话说,如果有 4 个纹
原帖: https://computergraphics.stackexchange.com/questions/4793/how-can-i-generate-mipmaps-manually 这是
您现在可能知道,当您使用 IDE 创建 Assets 时,android studio 1.1 在 mipmap-xxx 文件夹而不是 drawable-xxx 文件夹中创建新的图像 Assets 。
我目前正在使用自动 mipmap 生成(C# + OpenTK): GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); 我使用的纹理被平铺成 16px
mipmap 是否仅用于应用程序 luancher 图标,例如,如果我将图像用于按钮,该图像是否也应该转到 mipmap 目录或 drawble 文件夹? 换句话说:mipmap 是否替换了 draw
这个问题在这里已经有了答案: Mipmap drawables for icons (12 个回答) 关闭7年前。 我正在使用 Android Studio 1.1 Preview 1。我注意到,当我
我在我的 Visual Studio 中包含了演示项目。但它在以下陈述中向我展示了错误。我也将图像和过去复制到 mipmap 中。拜托,任何人都可以检查出什么错误并指导我。提前谢谢你。 Bitma
我已经在 Android Studio 上创建了 Android 项目。但是没有放置app图标的mipmap文件夹。 这是否意味着我必须创建 mipmap 文件夹?还是项目设置有问题? 最佳答案 如果
我是 'wpf' 的新手,我遇到了以下问题:在我的项目中,我尝试使用小分辨率 .png 作为模型的纹理。当我在 Blender(我构建立方体的地方)中禁用 mipmapping 时,结果正是我想要的:
我正在尝试更改我的应用程序的图标。我添加了一个新的“Image Asset”,它生成不同的图标大小并将它们放在 mipmaps 文件夹中。 (mipmap-hdpi、mipmap-mdpi、...)。
我已经使用 webgl 做了很多工作,但现在它是第一次使用 dart,我遇到了一个奇怪的错误。我创建一个像这样的默认纹理: GlTexture() { mTexture = gl.crea
同时调用时 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_
同时调用时 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_
mipmap 的唯一真正优势是实时所需的过滤要求较低,因为它已经部分提前完成了吗? 您不能通过线性或各向异性过滤以及更多的处理能力获得相同的结果吗? 最佳答案 不是“一点点”更多的处理能力,而是更多的
我正在向您咨询是否有一个简洁的 numpy 解决方案可以使用双线性过滤来缩小 2D numpy 数组(这是一个图像)的大小? 更具体地说,我的数组的形状为 (width, height, 4)(如 r
我的 mipmapping 工作正常。但出于某种原因,在我应用纹理后,应用程序中的所有其他对象都呈现出纹理的平均颜色。甚至平视显示器。有什么我需要考虑的吗?这是代码: GLuint LoadTextu
我是一名优秀的程序员,十分优秀!