在openGL(版本>3.3)的屏幕上显示纹理时如何更改纹理的大小?
How to change the size of the texture when displayed it on the screen in openGL (version> 3.3)?
如何更改屏幕上纹理的大小?我想制作一个在OpenGL中学习的2d小游戏。:-)我试图改变顶点[]的几何结构,但纹理无法延伸到它。我使用的代码如下:
tempz = IMG_Load("graphics/menu_start.png");
SDL_InvertSurface(tempz);
//setup quad geometry
//setup quad vertices
vertices[0] = Vector2D(0.0,0.0);
vertices[1] = Vector2D(1.0,0.0);
vertices[2] = Vector2D(1.0,1.0);
vertices[3] = Vector2D(0.0,1.0);
//fill quad indices array
GLushort* id = &indices[0];
*id++ =0;
*id++ =1;
*id++ =2;
*id++ =0;
*id++ =2;
*id++ =3;
//setup quad vao and vbo stuff
glGenVertexArrays(1, &vaoID);
glGenBuffers(1, &vboVerticesID);
glGenBuffers(1, &vboIndicesID);
glBindVertexArray(vaoID);
glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID);
//pass quad vertices to buffer object
glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
//enable vertex attribute array for position
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE,0,0);
//pass quad indices to element array buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
int texture_width = 0, texture_height = 0, channels=0;
texture_width = tempz->w;
texture_height = tempz->h;
//setup OpenGL texture and bind to texture unit 0
glGenTextures(1, &textureID);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
//set texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//allocate texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tempz->pixels);
programID = LoadShaders( "shaders/shader.vert", "shaders/shader.frag" );
glUseProgram(programID);
如果发布其余部分(例如着色器)会有所帮助,但我觉得奇怪的是,顶点中没有纹理坐标。通常情况下,它们在拐角处为(0,0)、(0,1),(1,0)和(1,1)。这些是顶点中的属性,就像物理位置一样。然后,你可以在整个地方摆动物理位置,仍然可以看到纹理以同样的方式映射到脸上。
相关文章:
- OpenGL大的3D纹理(>2GB)非常慢
- OpenGL将纹理四边形渲染为(0,0)
- OpenGL 4.3 错误地将第 4 个纹理坐标映射到与第 3 个纹理坐标相同的位置
- Qt OpenGL 渲染到纹理性能问题
- 使用 C++在 OpenGL 中对 3D 多边形进行纹理处理
- 无法获取要在 OpenGL ES2 中显示的 RGB 纹理
- 在 OpenGL 中加载纹理C++
- 添加新纹理OpenGL时,模型消失了
- 初始化多个纹理 OpenGL、SDL C++ 时出现问题
- 将多个纹理 OpenGL 绑定到不同的四边形
- 如何加载纹理Opengl
- 读写一个纹理(OpenGL)
- 渲染时加载纹理 (OpenGL)
- 如何绑定纹理openGL的一部分
- 将两个图像堆栈的非电源加载到 3D 纹理 OpenGL C++
- 我的精灵在纹理opengl之间切换
- 使用深度纹理OpenGL/GLSL的深度遮挡(3.3/330)
- 加载多纹理opengl 2.0
- 将位置写入纹理OpenGL/GLSL
- 为纹理OpenGL C++加载多个.bmp文件时出现问题