这是我的源代码.它仍然无法正常工作.我想在一个立方体的6面上放置6张不同的图片,这是动画的.请帮忙 :)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>WebGL</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="glMatrix-0.9.5.min.js"></script>
<script type="text/javascript" src="webgl-utils.js"></script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
void main(void) {
gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTextureCoord;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
vTextureCoord = aTextureCoord;
}
</script>
<script type="text/javascript">
var …
Run Code Online (Sandbox Code Playgroud) 我在将等距柱状图全景图像映射到简单平面上时遇到了很多麻烦。到目前为止,我的映射是正确的,所以一切都准确地显示在它应该的位置。但我的问题是,在我的纹理坐标从 1 跳到 0 的地方有一条线。但那条线不仅仅是一些线。它的像素比普通像素大一倍。我将它直接渲染到我的屏幕上,中间没有帧缓冲区。我试图启用多重采样,但它根本不影响那条线。我也试图通过将它隐藏在我的相机后面来摆脱那条线,但后来我意识到当我抬头时,无论我在哪里转动它,总会有这条线。在我的代码中,当我使用例如“if”或“atan”进行纹理坐标跳转时,总是显示这一行。
我想涉足 OpenGL 项目中的一些程序纹理,但似乎没有任何效果。我所需要的只是将 RGB 和可能的 A 值输入到空纹理中,而不是从文件加载它。在实际的代码中我该如何做到这一点?
编辑:还没有主要代码,因为我没有发现任何有用的东西。目前最好的猜测是这样的:
void GenerateTexture()
{
unsigned char image_data[16] = {0, 0, 150, 255, 125, 0, 0, 255, 0, 0, 150, 255, 125, 0, 0, 255};
glGenTextures(1, &tex_obj);
glBindTexture(GL_TEXTURE_2D, tex_obj);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
}
Run Code Online (Sandbox Code Playgroud)
...像这样实现:
glBegin (GL_QUADS);
if (*irrelevant for question*){
glTexCoord2f(0.0,1.0);
glVertex3f (-0.45-cam.pos.val[0], 0.45-cam.pos.val[1], 0.45-cam.pos.val[2]);
glTexCoord2f(0.0,0.0);
glVertex3f (-0.45-cam.pos.val[0], -0.45-cam.pos.val[1], 0.45-cam.pos.val[2]);
glTexCoord2f(1.0,0.0);
glVertex3f (0.45-cam.pos.val[0], -0.45-cam.pos.val[1], 0.45-cam.pos.val[2]);
glTexCoord2f(1.0,1.0);
glVertex3f (0.45-cam.pos.val[0], 0.45-cam.pos.val[1], 0.45-cam.pos.val[2]);
}
glEnd ();
Run Code Online (Sandbox Code Playgroud)
...但是一旦使用超过 1x1 的纹理运行,它就会变成干净的白色。
我想在我的场景中添加多个纹理我有一个纹理工作,但我不知道如何包含其他纹理.
#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>
#include <stdlib.h>
#include <iostream>
void init(void);
void display(void);
void keyboard(unsigned char, int, int);
void resize(int, int);
void drawcube(float, float, float, float, float, float, int);
int is_depth;
#define ROAD 0
struct Image
{
unsigned long size_x;
unsigned long size_y;
char *data;
};
typedef struct Image Image;
const int textureCount = 1;
Image myTextureData[textureCount];
GLuint theTexture[textureCount];
char* textureFilenames[textureCount] = {"road.bmp"};
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(40, …
Run Code Online (Sandbox Code Playgroud) 终于有时间玩着色器,但一时间卡住了.我想将顶点传递给着色器并在其上制作一些gpgpu.
Gpgpu工作正常,我猜是因为我看到几个像素,中间的一个被推到一边,因为我放入代码只是为了测试.
现在我想传递球体顶点.以下是我要采取的步骤.请指出错误:-)
编辑:小提琴添加 - 点击这里
1)创建几何体,并将其传递给数据数组.
geometry = new THREE.SphereGeometry( 0.2, 15, 15 );
console.log(geometry.vertices.length);
var a = new Float32Array(geometry.vertices.length * 4);
for(var k=0; k<geometry.vertices.length; k++) {
a[ k*4 + 0 ] = geometry.vertices[k].x;
a[ k*4 + 1 ] = geometry.vertices[k].y;
a[ k*4 + 2 ] = geometry.vertices[k].z;
a[ k*4 + 3 ] = 1;
}
Run Code Online (Sandbox Code Playgroud)
2)将其保存在数据纹理中
posTexture[2] = new THREE.DataTexture(a, 16, 16, THREE.RGBAFormat, THREE.FloatType);
Run Code Online (Sandbox Code Playgroud)
3)设置'Set scene'(它应该将datatexture传递给它一次)setUniforms = {posTexture:{type:"t",value:posTexture [2]}};
var setMaterial = new THREE.ShaderMaterial({
uniforms: setUniforms,
vertexShader: document.getElementById('setVert').textContent, …
Run Code Online (Sandbox Code Playgroud) 我刚刚创建了一个 Metal 模板并稍微更改了代码。我用 Minecraft 16x16 青金石矿石纹理切换了默认颜色图,但由于某种原因,它们在低分辨率时会变得模糊。我正在尝试实现像素化的 Minecraft 外观,因此想知道如何禁用这种模糊/过滤。
有没有办法加载/呈现资产而不产生这种模糊?这是我的加载资产函数:
class func loadTexture(device: MTLDevice, textureName: String) throws -> MTLTexture {
/// Load texture data with optimal parameters for sampling
return try MTKTextureLoader(device: device).newTexture(name: textureName, scaleFactor: 1.0, bundle: nil, options: [
MTKTextureLoader.Option.textureUsage: NSNumber(value: MTLTextureUsage.shaderRead.rawValue),
MTKTextureLoader.Option.textureStorageMode: NSNumber(value: MTLStorageMode.`private`.rawValue)
])
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的模糊立方体的屏幕截图: