我需要在单个元素中重复纹理.它甚至可以在WebGL中使用吗?
我试过以下任何一种但没有运气.
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_S, ctx.CLAMP_TO_EDGE);
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_T, ctx.CLAMP_TO_EDGE);
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_S, ctx.REPEAT);
ctx.texParameteri(ctx.TEXTURE_2D, ctx.TEXTURE_WRAP_T, ctx.REPEAT);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我正在尝试Texture2D使用 .png加载(.png) 资源Resource.Load。我试过以下路径模式:
Assets/CaseSensitivePath/TextureName
CaseSensitivePath/TextureName
Assets/CaseSensitivePath/TextureName.png
CaseSensitivePath/TextureName.png
Run Code Online (Sandbox Code Playgroud)
每次都Resource.Load(path, typeof(Texture2D))返回null。这是我的代码和错误处理:
public class LazyResource<T> where T : UnityEngine.Object
{
//Path is read-only
public string path { get { return _path; } }
private string _path = "";
//Whether NOT FOUND warning was thrown
//in that case, further load attemts are ommited and the resource returns always null...
public bool failed = false;
//Constructor uses the path as first parameter
public LazyResource(string path) {
_path = path; …Run Code Online (Sandbox Code Playgroud) 我主要是一个程序员,不太擅长绘图,所以我决定在运行时以程序方式制作纹理,我的意思是每次都生成一些新的和新鲜的东西,它应该看起来可信。如何获得从这个开始?在 Unity 中编程,如果这会有所帮助的话。
我正在尝试使用texture2D()从计算着色器中的sampler2d纹理读取值。在PC上运行正常,但在android移动设备(使用310 es版本)上,相同代码的编译失败,并出现以下错误:
'texture2D' : type is for Vulkan api only
Run Code Online (Sandbox Code Playgroud)
这个调用与计算着色器不兼容吗?
我正在尝试从 Unreal Engine C++ 项目中填充的 UTexture2D 读取像素数据。在我在这里发布问题之前,我尝试使用此链接中描述的方法:https : //answers.unrealengine.com/questions/25594/accessing-pixel-values-of-texture2d.html。但是,它对我不起作用。我从纹理中得到的所有像素值都是一些垃圾数据。
我只想从 SceneCapture2D 和包含 SceneTexture: Depth 节点的后处理材料中获取深度值。我需要 C++ 中可用的深度值,以便我可以使用 OpenCV 进行进一步处理。在 Directx11 中,staging 纹理可用于 CPU 读取,但在虚幻引擎中,我不知道如何像 Dx11 那样创建“staging 纹理”。我无法从当前方法中获得正确的像素值,这让我觉得我可能会尝试访问非 CPU 可读的纹理。
这是我从 RGB UTexture2D 读回数据的实验代码。
初始化 RGB 纹理:
VideoTextureColor= UTexture2D::CreateTransient(640, 480, PF_B8G8R8A8);
VideoTextureColor->UpdateResource();
VideoUpdateTextureRegionColor = new FUpdateTextureRegion2D(0, 0, 0, 0, 640, 480);
ColorRegionData = new FUpdateTextureRegionsData;
PixelDepthData.Init(FColor(0, 0, 0, 255), 640 * 480);
// Populate the texture with blue color
for (int i = 0; i < 640; i++) { …Run Code Online (Sandbox Code Playgroud) 我是Direct X 11的新手。我想创建一个简单的2D纹理(类型为ID3D11Texture2D)。我已经阅读了有关CreateTexture2D的文档,并且我了解:
pDesc是我们定义图像的方式。
pInitialData包含表示图像纹理的每个像素的字节数组
ppTexture2D是我们的结果-DirectX 11的2D纹理。
我想创建一个非常简单的2D纹理:粉色矩形。但是我不知道如何为粉红色矩形创建字节数组。我有下面的代码:
D3D11_TEXTURE2D_DESC Desc;
D3D11_SUBRESOURCE_DATA InitialData;
ID3D11Texture2D* pTexture2D;
Desc.Usage = D3D11_USAGE_DEFAULT;
BYTE* array;//How to have an array of Pink rectangle?
InitialData.pSysMem = array;
InitialData.SysMemPitch = 0;
InitialData.SysMemSlicePitch = 0;
m_device->CreateTexture2D(&Desc, &InitialData, &pTexture2D);//ID3D11Device m_device has been created before.
Run Code Online (Sandbox Code Playgroud)
非常感谢你。
对不起,如果我的问题没有清除.让我详细说明一下.
我有一个100 x 200的矩形,我有一个100 x 200的图形尺寸,适合矩形.由于OpenGL要求所有纹理都具有2 ^ n的宽度和高度,因此我基本上将100 x 200图形右侧放入128 x 256图像中.它适用于OpenGL,因为我只是要求它只绘制矩形所需的纹理的一部分.但是,让我印象深刻的是,在128 x 256纹理中,有很多未使用的空间.
在这种情况下,有没有更好的方法来处理这些未使用的空间?或者这应该是要走的路?
我可以很容易地想到在一些情况下改变a中的单个像素是有用的Texture2D,特别是因为在不断地做GetData<>(); SetData<>();每一帧或绘图时你会遇到的性能损失和不便RenderTarget2D.
有没有真正的理由不公开单个像素的setter方法?如果没有,有没有办法修改单个像素而不使用上述方法?
我需要为学生项目使用 OpenGL 编写一个小游戏。我还必须使用 CMake 来完成这个项目。我包含了用于导入纹理的 stb_image.c。
我将以下几行添加到我的 CMakeList.txt 中
include_directories(${CMAKE_SOURCE_DIR}/../extern/stb_image)
link_directories(${CMAKE_SOURCE_DIR}/../extern/stb_image)
Run Code Online (Sandbox Code Playgroud)
并将 stb_image.h 包含到我的项目文件中。代码编译没有错误。现在我尝试使用以下代码将纹理导入到我的项目中。
#include "stb_image.h"
int x, y, n;
unsigned char *data = stbi_load("testTexture.png" , &x, &y, &n, 0);
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用“make”命令编译项目,则会收到以下错误:
Linking CXX executable /Users/.../Documents/.../.../.../binaries/basic-texturing
Undefined symbols for architecture x86_64:
"_stbi_load", referenced from:
loadObjectsAndTextures() in inits.cc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/.../Documents/.../.../.../binaries/basic-texturing] Error 1
make[1]: *** [CMakeFiles/basic-texturing.dir/all] Error 2
make: *** [all] …Run Code Online (Sandbox Code Playgroud) 我开发了一个用于保存纹理(屏幕截图)的应用程序,我需要对其进行压缩,但是-我无法使用EncodeToPNGmethod来在屏幕上显示图像。
我的步骤:
Texture2D tex = new Texture2D(recwidth, recheight,
TextureFormat.RGB24, false); // RGB24-由于下一步:
tex.ReadPixels(rex, rdPXX, rdPXY);
tex.Apply();
tex.Compress(false); 稍后,我需要在屏幕上显示-
var bytes = tex.EncodeToPNG();但是我不能,因为众所周知EncodeToPNG,不支持压缩纹理,该怎么办?我的手机占用很多空间