glTexSubImage2D的使用详解

2023-11-07

Name
glTexSubImage2D, glTextureSubImage2D — specify a two-dimensional texture subimage

C Specification
void glTexSubImage2D( GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const void * pixels);

void glTextureSubImage2D( GLuint texture,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const void *pixels);

Parameters
target
Specifies the target to which the texture is bound for glTexSubImage2D. Must be GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, or GL_TEXTURE_1D_ARRAY.

texture
Specifies the texture object name for glTextureSubImage2D. The effective target of texture must be one of the valid target values above.

level
Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.

xoffset
Specifies a texel offset in the x direction within the texture array.

yoffset
Specifies a texel offset in the y direction within the texture array.

width
Specifies the width of the texture subimage.

height
Specifies the height of the texture subimage.

format
Specifies the format of the pixel data. The following symbolic values are accepted: GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_DEPTH_COMPONENT, and GL_STENCIL_INDEX.

type
Specifies the data type of the pixel data. The following symbolic values are accepted: GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, and GL_UNSIGNED_INT_2_10_10_10_REV.

pixels
Specifies a pointer to the image data in memory.

Description
Texturing maps a portion of a specified texture image onto each graphical primitive for which texturing is enabled.

glTexSubImage2D and glTextureSubImage2D redefine a contiguous subregion of an existing two-dimensional or one-dimensional array texture image. The texels referenced by pixels replace the portion of the existing texture array with x indices xoffset and xoffset+width−1, inclusive, and y indices yoffset and yoffset+height−1, inclusive. This region may not include any texels outside the range of the texture array as it was originally specified. It is not an error to specify a subtexture with zero width or height, but such a specification has no effect.

If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target (see glBindBuffer) while a texture image is specified, pixels is treated as a byte offset into the buffer object’s data store.

Notes
glPixelStore modes affect texture images.

glTexSubImage2D and glTextureSubImage3D specify a two-dimensional subtexture for the current texture unit, specified with glActiveTexture.

GL_STENCIL_INDEX is accepted for format only if the GL version is 4.4 or higher.

Errors
GL_INVALID_ENUM is generated if target or the effective target of texture is not GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, or GL_TEXTURE_1D_ARRAY.

GL_INVALID_OPERATION is generated by glTextureSubImage2D if texture is not the name of an existing texture object.

GL_INVALID_ENUM is generated if format is not an accepted format constant.

GL_INVALID_ENUM is generated if type is not a type constant.

GL_INVALID_VALUE is generated if level is less than 0.

GL_INVALID_VALUE may be generated if level is greater than log2 max, where max is the returned value of GL_MAX_TEXTURE_SIZE.

GL_INVALID_VALUE is generated if xoffset<−b, (xoffset+width)>(w−b), yoffset<−b, or (yoffset+height)>(h−b), where w is the GL_TEXTURE_WIDTH, h is the GL_TEXTURE_HEIGHT, and b is the border width of the texture image being modified. Note that w and h include twice the border width.

GL_INVALID_VALUE is generated if width or height is less than 0.

GL_INVALID_OPERATION is generated if the texture array has not been defined by a previous glTexImage2D operation.

GL_INVALID_OPERATION is generated if type is one of GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, or GL_UNSIGNED_SHORT_5_6_5_REV and format is not GL_RGB.

GL_INVALID_OPERATION is generated if type is one of GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, or GL_UNSIGNED_INT_2_10_10_10_REV and format is neither GL_RGBA nor GL_BGRA.

GL_INVALID_OPERATION is generated if format is GL_STENCIL_INDEX and the base internal format is not GL_STENCIL_INDEX.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the buffer object’s data store is currently mapped.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the data would be unpacked from the buffer object such that the memory reads required would exceed the data store size.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and pixels is not evenly divisible into the number of bytes needed to store in memory a datum indicated by type.

Associated Gets
glGetTexImage

glGet with argument GL_PIXEL_UNPACK_BUFFER_BINDING

Version Support
OpenGL Version
Function / Feature Name 2.0 2.1 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3 4.4 4.5
glTexSubImage2D ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
glTextureSubImage2D - - - - - - - - - - - ✔
See Also
glActiveTexture, glCopyTexImage1D, glCopyTexImage2D, glCopyTexSubImage1D, glCopyTexSubImage2D, glCopyTexSubImage3D, glPixelStore, glTexImage1D, glTexImage2D, glTexImage3D, glTexSubImage1D, glTexSubImage3D, glTexParameter

Copyright
Copyright © 1991-2006 Silicon Graphics, Inc. Copyright © 2010-2014 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.

中文翻译:
名称
glTexSubImage2D - 指定二维纹理子图像

C规范
void glTexSubImage2D(GLenum target,

                                          GLint level,

                                          GLint xoffset,

                                          GLint yoffset,

                                          GLsizei width,

                                          GLsizei height,

                                          GLenum format,

                                          GLenum type,

                                          const GLvoid * data);

参数
target

指定活动纹理单元的目标纹理。 必须是GL_TEXTURE_2D,GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,GL_TEXTURE_CUBE_MAP_POSITIVE_Z或GL_TEXTURE_CUBE_MAP_NEGATIVE_Z。

level

指定详细级别编号。 0级是基本图像级别。 级别n是第n个mipmap缩小图像。

xoffset

指定纹理数组中x方向的纹素偏移。

yoffset

指定纹理数组中y方向的纹素偏移。

width

指定纹理子图像的宽度。

height

指定纹理子图像的高度。

format

指定像素数据的格式。 接受以下符号值:GL_ALPHA,GL_RGB,GL_RGBA,GL_LUMINANCE和GL_LUMINANCE_ALPHA。

type

指定像素数据的数据类型。 接受以下符号值:GL_UNSIGNED_BYTE,GL_UNSIGNED_SHORT_5_6_5,GL_UNSIGNED_SHORT_4_4_4_4和GL_UNSIGNED_SHORT_5_5_5_1。

data

指定指向内存中图像数据的指针。

描述
纹理将指定纹理图像的一部分映射到纹理处于活动状态的每个图形基元上。 当前片段着色器或顶点着色器使用内置纹理查找功能时,纹理处于活动状态。

glTexSubImage2D重新定义了现有二维纹理图像的连续子区域。data引用的纹素将现有纹理数组的部分替换为x索引xoffset和xoffset + width - 1(含),y索引yoffset和yoffset + height - 1(含)。该区域可能不包括纹理数组范围之外的任何最初指定的那样的纹素。指定宽度或高度为零的子纹理不是错误的,但这样的规范是没有效果的。

注意
由glPixelStorei设置的存储参数GL_UNPACK_ALIGNMENT会影响从客户端内存中读取数据的方式。 有关说明,请参阅glPixelStorei。

glTexSubImage2D为当前纹理单元指定二维或立方体贴图子纹理,由glActiveTexture指定。

错误
GL_INVALID_ENUM :如果target不是GL_TEXTURE_2D,GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,GL_TEXTURE_CUBE_MAP_POSITIVE_Z或GL_TEXTURE_CUBE_MAP_NEGATIVE_Z。

GL_INVALID_ENUM :如果format或type不是可接受的值。

GL_INVALID_VALUE :level<0

GL_INVALID_VALUE :level>log以2为底,max的对数,其中max为GL_MAX_TEXTURE_SIZE返回的值

GL_INVALID_VALUE :xoffset < 0 , xoffset + width > w , yoffset < 0 , or yoffset + height > h,其中w是宽度,h是要修改的纹理图像的高度。

GL_INVALID_VALUE :如果width或height小于0。

GL_INVALID_OPERATION :如果纹理数组尚未由之前的glTexImage2D或glCopyTexImage2D操作定义(其内部格式与glTexSubImage2D的格式匹配)。

GL_INVALID_OPERATION:如果type为GL_UNSIGNED_SHORT_5_6_5且格式不是GL_RGB。

GL_INVALID_OPERATION :如果type为GL_UNSIGNED_SHORT_4_4_4_4或GL_UNSIGNED_SHORT_5_5_5_1且格式不是GL_RGBA。

相关Gets
glGet 参数GL_MAX_TEXTURE_SIZE 或GL_MAX_CUBE_MAP_TEXTURE_SIZE

另见
glActiveTexture,glCompressedTexImage2D,glCompressedTexSubImage2D,glCopyTexImage2D,glCopyTexSubImage2D,glPixelStorei,glTexImage2D,glTexParameter

版权
https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glTexSubImage2D.xml

https://blog.csdn.net/flycatdeng

Copyright © 1991-2006 Silicon Graphics, Inc.本文档的许可是根据SGI Free Software B License.详见http://oss.sgi.com/projects/FreeB/.

注意!!!

因为纹理坐标的(0,0)点是左下角,所以我们修改纹理数据的时候是从左下角开始绘制的。

顺序先沿着X轴从左至右,再沿着Y轴从下至上,即一行一行像素的绘制。

示例代码如下:

        virtual unsigned    loadTexture(const char* fileName)
        {
            unsigned    textureId   =   0;
            //1 获取图片格式
            FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(fileName, 0);

            //2 加载图片
            FIBITMAP    *dib = FreeImage_Load(fifmt, fileName,0);

            //3 转化为rgb 24色
            dib     =   FreeImage_ConvertTo24Bits(dib);

            //4 获取数据指针
            BYTE    *pixels =   (BYTE*)FreeImage_GetBits(dib);

            int     width   =   FreeImage_GetWidth(dib);
            int     height  =   FreeImage_GetHeight(dib);

			//windows是BGR模式
			for (int i =0;i<width*height*3;)
			{
				float temp = pixels[i+2];
				pixels[i + 2] = pixels[i];
				pixels[i] = temp;
				i += 3;
			}

            /**
            *   产生一个纹理Id,可以认为是纹理句柄,后面的操作将书用这个纹理id
            */
            glGenTextures( 1, &textureId );

            /**
            *   使用这个纹理id,或者叫绑定(关联)
            */
            glBindTexture( GL_TEXTURE_2D, textureId );
            /**
            *   指定纹理的放大,缩小滤波,使用线性方式,即当图片放大的时候插值方式 
            */
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
            
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
            /**
            *   将图片的rgb数据上传给opengl.
            */
            glTexImage2D( 
                GL_TEXTURE_2D,      //! 指定是二维图片
                0,                  //! 指定为第一级别,纹理可以做mipmap,即lod,离近的就采用级别大的,远则使用较小的纹理
                GL_RGB,             //! 纹理的使用的存储格式
                width,              //! 宽度,老一点的显卡,不支持不规则的纹理,即宽度和高度不是2^n。
                height,             //! 宽度,老一点的显卡,不支持不规则的纹理,即宽度和高度不是2^n。
                0,                  //! 是否的边
                GL_RGB,             //! 数据的格式,bmp中,windows,操作系统中存储的数据是bgr格式
                GL_UNSIGNED_BYTE,   //! 数据是8bit数据
                pixels
                );


			char    subData[100 * 100 * 3];

			memset(subData, 255, sizeof(subData));
			for (int i = 0; i<150;)
			{
				subData[i] = 0;
				subData[++i] = 0;
				subData[++i] = 255;
			}
			glTexSubImage2D(GL_TEXTURE_2D, 0, 100, 50, 100, 100, GL_RGB, GL_UNSIGNED_BYTE, subData);
            /**
            *   释放内存
            */
            FreeImage_Unload(dib);
            return  textureId;
        }

图片修改结果如下:
在这里插入图片描述
二、在freetype中应用的时候要注意了!!!
代码如下

int _yStart = 0;
int _xStart = 0;
	char* readFile(const char* fileName, unsigned& length)
	{
		FILE* pFile = fopen(fileName, "rb");
		if (pFile)
		{
			fseek(pFile, 0, SEEK_END);
			length = ftell(pFile);
			fseek(pFile, 0, SEEK_SET);
			char*buffer = new char[length + 1];
			fread(buffer, 1, length, pFile);
			buffer[length] = 0;
			fclose(pFile);
			return buffer;
		}
		else
		{
			char buffer[1024];
			sprintf_s(buffer, "read %s failed", fileName);
			assert(pFile != 0 && buffer);
		}
		return 0;
	}
	void buildSystemFont(const char* font,int fontSize)
	{
		_uiProgram.initialize();

		unsigned length = 0;
		_fontBuffer = readFile(font, length);

		/**
		*   保存字体的大小
		*/
		_fontSize = fontSize;
		/**
		*   已经创建了字体则销毁
		*   支持多次调用
		*/
		if (_face)
		{
			FT_Done_Face(FT_Face(_face));
			_xStart = 0;
			_yStart = 0;
			memset(_character, 0, sizeof(_character));
		}
		/**
		*   销毁字体
		*/
		if (_sysFontTexture != -1)
		{
			glDeleteTextures(1, &_sysFontTexture);
		}
		glGenTextures(1, &_sysFontTexture);
		/**
		*   使用这个纹理id,或者叫绑定(关联)
		*/
		glBindTexture(GL_TEXTURE_2D, _sysFontTexture);
		/**
		*   指定纹理的放大,缩小滤波,使用线性方式,即当图片放大的时候插值方式
		*/
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexImage2D(
			GL_TEXTURE_2D, 
			0, 
			GL_ALPHA, 
			_textureWidth,
			_textureHeight, 
			0, 
			GL_ALPHA, 
			GL_UNSIGNED_BYTE, 
			0
			);

		FT_Error error = FT_New_Memory_Face((FT_Library)_library,(const FT_Byte*)_fontBuffer,length,0,&(FT_Face)_face);
		if (error != 0)
		{
			return;
		}
		FT_Face ftFace = (FT_Face)_face;
		FT_Select_Charmap(ftFace, FT_ENCODING_UNICODE);
		FT_F26Dot6 ftSize = (FT_F26Dot6)(fontSize * (1 << 6));

		FT_Set_Char_Size((FT_Face)_face, ftSize, 0, 72, 72);

		assert(_face != 0);

	}

Character getCharacter(wchar_t ch)
	{
		if (_character[ch].x0 == 0 &&
			_character[ch].x0 == 0 &&
			_character[ch].x1 == 0 &&
			_character[ch].y1 == 0
			)
		{
			glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

			if (_xStart + max(_fontPixelX, _fontSize) > _textureWidth)
			{
				/**
				*   写满一行,从新开始
				*/
				_xStart = 0;
				/**
				*   y开始位置要增加
				*/
				_yStart += max(_fontPixelY, _fontSize);
			}
			FT_Load_Glyph(_face, FT_Get_Char_Index(_face, ch), FT_LOAD_DEFAULT);
			FT_Glyph glyph;
			FT_Get_Glyph(FT_Face(_face)->glyph, &glyph);
			/**
			*   根据字体的大小决定是否使用反锯齿绘制模式
			*   当字体比较小的是说建议使用ft_render_mode_mono
			*   当字体比较大的情况下12以上,建议使用ft_render_mode_normal模式
			*/
			if (!(ch >= L'0' && ch <= L'9'))
			{
				FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1);
			}
			else
			{
				FT_Glyph_To_Bitmap(&glyph, ft_render_mode_mono, 0, 1);
			}
			FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
			FT_Bitmap& bitmap = bitmap_glyph->bitmap;
			FT_Bitmap ftBitmap;
			FT_Bitmap_New(&ftBitmap);

			if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
			{
				if (FT_Bitmap_Convert((FT_Library)_library, &bitmap, &ftBitmap, 1) == 0)
				{
					/**
					*   Go through the bitmap and convert all of the nonzero values to 0xFF (white).
					*/
					for (unsigned char* p = ftBitmap.buffer, *endP = p + ftBitmap.width * ftBitmap.rows; p != endP; ++p)
						*p ^= -*p ^ *p;
					bitmap = ftBitmap;
				}
			}
			/**
			*   如果没有数据,则不写,直接过去
			*/
			if (bitmap.width == 0 || bitmap.rows == 0)
			{

				char    mem[1024 * 32];
				memset(mem, 0, sizeof(mem));
                
				_character[ch].x0 = _xStart;
				_character[ch].y0 = _yStart;
				_character[ch].x1 = _xStart + _fontSize / 2;
				_character[ch].y1 = _yStart + _fontSize - 1;
				_character[ch].offsetY = _fontSize - 1;
				_character[ch].offsetX = 0;

				glBindTexture(GL_TEXTURE_2D, _sysFontTexture);

				glTexSubImage2D(
					GL_TEXTURE_2D,
					0,
					_xStart,
					_yStart,
					_fontSize / 2,
					_fontSize,
					GL_ALPHA,
					GL_UNSIGNED_BYTE,
					mem
				);
				_xStart += _fontSize / 2;

			}
			else
			{
				glBindTexture(GL_TEXTURE_2D, _sysFontTexture);

				_character[ch].x0 = _xStart;
				_character[ch].y0 = _yStart;
				_character[ch].x1 = _xStart + bitmap.width;
				_character[ch].y1 = _yStart + bitmap.rows;

				_character[ch].offsetY = bitmap_glyph->top;
				_character[ch].offsetX = bitmap_glyph->left;

				glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
				glTexSubImage2D(
					GL_TEXTURE_2D,
					0,
					_xStart,
					_yStart,
					max(1, bitmap.width),
					max(1, bitmap.rows),
					GL_ALPHA,
					GL_UNSIGNED_BYTE,
					bitmap.buffer
				);
				_xStart += (bitmap.width + 1);
				_fontPixelY = max(_fontPixelY, bitmap.rows);
				_fontPixelX = max(_fontPixelX, bitmap.width);
			}

			FT_Bitmap_Done((FT_Library)_library, &ftBitmap);
		}
		return  _character[ch];
	}

主要的内容在getCharacter函数,将字库里的数据,通过glTexSubImage2D贴到我们自己的纹理上。

但由于glTexSubImage2D绘制的特性(从下往上),所以我们的字是倒过来的。
在这里插入图片描述

我们再使用该纹理写字的时候务必注意倒过来

参考:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/
https://blog.csdn.net/flycatdeng/article/details/82667353
https://blog.csdn.net/Qinhaifu/article/details/102994102

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

glTexSubImage2D的使用详解 的相关文章

  • 在 3D 场景中实现“抓取”相机平移工具

    在我的场景中 我有想要 抓取 的地形 然后在移动光标时让相机平移 其高度 视图向量 视野等全部保持不变 因此 最初的 抓取 点将是世界空间中的工作点 我希望在拖动时该点保留在光标下方 我当前的解决方案是获取前一个和当前的屏幕点 取消投影它们
  • OpenGL中背景对象绘制在前景对象前面?

    为了测试目的 我们假设我画了 2 个茶壶glutSolidTeapot 像这样 glColor3f 1 0f 0 0f 0 0f Red teapot glutWireTeapot 1 0f glColor3f 0 0f 1 0f 0 0f
  • GL_COLOR_ATTACHMENT 有什么作用?

    我现在正在学习帧缓冲区 但我只是不明白颜色附件的作用 我了解帧缓冲区 第二个参数的意义是什么 glFramebufferTexture2D GL FRAMEBUFFER GL COLOR ATTACHMENT0 GL TEXTURE 2D
  • 如何在opengl中使用四元数绕屏幕中心旋转?

    我正在尝试实现轨迹球 轨迹球旋转 但我的中心有问题 回转 无论如何 我希望中心成为屏幕的中心 让我解释一下到目前为止我所做的事情 我创建了一个四元数 旋转轴 向量起点x向量结束 角度 向量起点 向量结束 从该四元数中 我创建了一个旋转矩阵
  • 具有交错缓冲区的 openGL glDrawElements

    到目前为止 我只使用了 glDrawArrays 并希望转向使用索引缓冲区和索引三角形 我正在绘制一个有点复杂的对象 其中包含纹理坐标 法线和顶点坐标 所有这些数据都收集到一个交错的顶点缓冲区中 并使用类似于以下的调用进行绘制 假设所有血清
  • 为什么 cudaGLSetGLDevice 失败,即使它是在 main 函数的第一行中调用的

    我想使用 OpenGL 和 CUDA 之间的互操作性 我知道 正如一些教程所说 第一步是选择设备 但是 当我在主函数的第一行中调用 cudaGLSetGLDevice 0 时 程序退出并显示信息 cudaSafeCall 运行时 API 错
  • OpenSceneGraph 将相机设置在初始位置

    我是第一次使用 OpenSceneGraph 我有点迷失 因为文档确实不太清楚 所以 我有这段代码加载一个带有房子的 obj 文件 并且我在我想要的 人 所在的地方淹没了一个小盒子 所以现在 我不想把那个盒子放在那里 而是想把相机放在那里
  • Windows 上的 OpenGL SDK

    我正在尝试编写一个 OpenGL 应用程序 因此我安装了 Windows 7 SDK 然而 它似乎是OpenGL 1 1 define GL VERSION 1 1 1 如何找到我安装的 OpenGL 版本 dll 以及在哪里可以找到较新的
  • 使用普通画布/文本输出更新LayeredWindow

    有没有一种方法可以使用画布在表单上绘图 然后使用 updatelayeredwindow 这样表单就不可见 但文本可见 就像只显示文本的半透明表单一样 如果没有 那么有没有办法只用画布 opengl directx 制作某种半透明形式 我想
  • 仅在发布模式下使用 glGenBuffer 时出现未处理的异常 - QT

    我在 Windows 7 上使用 Qt 4 8 发布模式编译项目时遇到了一些问题 调试时一切正常 但在发布时我收到未处理的异常 0xC0000005 访问冲突 我将范围缩小到发生这种情况的行 即生成像素缓冲区的时间 我的第一个猜测是 DLL
  • OpenGL 与 OpenCL,选择哪个以及为什么?

    哪些功能使 OpenCL 能够独特地选择 OpenGL 和 GLSL 进行计算 尽管有与图形相关的术语和不实用的数据类型 OpenGL 是否有任何真正的警告 例如 可以通过使用其他纹理将 a 渲染到纹理来完成并行函数评估 减少操作可以通过迭
  • 无法在 Linux 的 NetBeans 中编译 C++ 和 OpenGL (GLFW) 的简单源代码

    我开始学习 OpenGL glfw 我从教程中复制源代码并尝试编译它 但出现了错误 我想我已经正确安装了所有头文件 glm glfw 等 这是我的来源 我没有在头文件中使用这些字符 include iostream include stdi
  • GLSL memoryBarrierShared() 有用吗?

    我想知道 memoryBarrierShared 的用处 事实上 当我查找屏障功能的文档时 我读到 对于计算着色器中任何给定的静态屏障实例 单个工作组内的所有调用都必须进入该实例 然后才能允许任何调用继续超出该实例 这确保了在给定的屏障静态
  • OpenGL/GLSL - 纹理过滤的实现

    我想在 GLSL 着色器中自己实现纹理过滤 min 和 magfilter 因为我想使用 image load and store 而不是采样器 而且我想以特殊方式处理未定义的像素 并且我正在寻找一篇文章或者这样讨论过滤过程 我记得如何从我
  • 3D 图形批处理

    很多网站 文章都说 批量 批 批 有人可以解释一下着色器中的 批处理 代表什么吗 即 是否 改变纹理 更改任意着色器变量 意味着某些东西不能 批处理 最简单的总结方法就是尝试尽可能少地调用 API 来绘制您需要绘制的内容 使用顶点数组或 V
  • Libgdx SpriteBatch.draw() 指定 4 个顶点

    我正在使用 libGdx 创建一个 2d 游戏 并尝试使用这个特殊的方法来绘制一个简单的 2d 纹理 分别指定 4 个顶点 draw Texture texture float spriteVertices int offset int l
  • 改进OpenGL粒子系统

    我正在寻找一种提高粒子系统性能的方法 因为它在 FPS 方面的成本非常高 这是因为我打电话 glDrawElements GL TRIANGLE STRIP mNumberOfIndices GL UNSIGNED SHORT 0 我为应用
  • 顶点着色器中的透视划分?

    当在顶点着色器中使用透视矩阵时 我应该编写代码来除以 w 还是在稍后阶段自动完成 我的问题的原因是我看到很多顶点着色器使用 gl Position matrix pos 如果后面有一个阶段将向量除以它的 w 分量 这就有意义了 然而 直到我
  • 如何获取片段的当前颜色?

    我正在尝试了解 GLSL 中的着色器 并且找到了一些有用的资源和教程 但我一直在寻找一些应该是基本且微不足道的东西 我的片段着色器如何检索当前片段 你通过说设置最终颜色gl FragColor whatever 但显然这是一个仅输出值 如何
  • GCC、字符串化和内联 GLSL?

    我想使用宏字符串化来声明内联 GLSL 着色器字符串 define STRINGIFY A A const GLchar vert STRINGIFY version 120 n attribute vec2 position void m

随机推荐