GlBindTexture: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "'''_glBindTexture:''' bind a named texture to a texturing target {{PageSyntax}} :: SUB '''_glBindTexture''' (BYVAL target AS _UNSIGNED LONG, BYVAL texture AS _UNSIGNED LONG) :: void '''_glBindTexture'''(GLenum {{Parameter|target}}, GLuint {{Parameter|texture}}); ; target : Specifies the target to which the texture is bound. Must be either {{KW|_GL_TEXTURE_1D}}, {{KW|_GL_TEXTURE_2D}}, {{KW|_GL_TEXTURE_3D}}, or {{KW|_GL_TEXTURE_1D_ARRAY}}, {{KW|_GL_TEXTURE_2D_ARRAY}},...")
 
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''_glBindTexture:''' bind a named texture to a texturing target
{{DISPLAYTITLE:_glBindTexture}}
The '''_glBindTexture''' statement enables the creation of a named texture that is bound to a texture target.




{{PageSyntax}}
{{PageSyntax}}
: [[_glBindTexture]] GLenum {{Parameter|target}}, GLuint {{Parameter|texture}}


:: SUB '''_glBindTexture''' (BYVAL target AS _UNSIGNED LONG, BYVAL texture AS _UNSIGNED LONG)
:: void '''_glBindTexture'''(GLenum {{Parameter|target}}, GLuint {{Parameter|texture}});


 
{{PageParameters}}
; target
* OpenGL is using its own set of variable types to describe its command parameters.
: Specifies the target to which the texture is bound. Must be either {{KW|_GL_TEXTURE_1D}}, {{KW|_GL_TEXTURE_2D}}, {{KW|_GL_TEXTURE_3D}}, or {{KW|_GL_TEXTURE_1D_ARRAY}}, {{KW|_GL_TEXTURE_2D_ARRAY}}, {{KW|_GL_TEXTURE_RECTANGLE}}, {{KW|_GL_TEXTURE_CUBE_MAP}}, {{KW|_GL_TEXTURE_2D_MULTISAMPLE}}, {{KW|_GL_TEXTURE_2D_MULTISAMPLE_ARRAY}}, {{KW|_GL_TEXTURE_BUFFER}}, or {{KW|_GL_TEXTURE_CUBE_MAP_ARRAY}}.
* Use the following table to find the respective QB64 [[Variable Types]].
; texture
{{OpenGLTypesPlugin}}
: Specifies the name of a texture.




{{PageDescription}}
{{PageDescription}}
* OpenGL's documentation is available in several places, so we won't reproduce it here for another time.
* The full description for this command can be found at [https://learn.microsoft.com/en-us/windows/win32/opengl/glbindtexture Microsoft Docs] and is also valid for QB64 usage.


'''_glBindTexture''' lets you create or use a named texture. Calling '''_glBindTexture''' with {{Parameter|target}} set to {{KW|_GL_TEXTURE_1D}}, {{KW|_GL_TEXTURE_2D}}, {{KW|_GL_TEXTURE_3D}}, or {{KW|_GL_TEXTURE_1D_ARRAY}}, {{KW|_GL_TEXTURE_2D_ARRAY}}, {{KW|_GL_TEXTURE_RECTANGLE}}, {{KW|_GL_TEXTURE_CUBE_MAP}}, {{KW|_GL_TEXTURE_2D_MULTISAMPLE}} or {{KW|_GL_TEXTURE_2D_MULTISAMPLE_ARRAY}} and {{Parameter|texture}} set to the name of the new texture binds the texture name to the target. When a texture is bound to a target, the previous binding for that target is automatically broken.
Texture names are unsigned integers. The value zero is reserved to represent the default texture for each texture target. Texture names and the corresponding texture contents are local to the shared object space of the current GL rendering context; two rendering contexts share texture names only if they explicitly enable sharing between contexts through the appropriate GL windows interfaces functions.
You must use {{KW|_glGenTextures}} to generate a set of new texture names.
When a texture is first bound, it assumes the specified target: A texture first bound to {{KW|_GL_TEXTURE_1D}} becomes one-dimensional texture, a texture first bound to {{KW|_GL_TEXTURE_2D}} becomes two-dimensional texture, a texture first bound to {{KW|_GL_TEXTURE_3D}} becomes three-dimensional texture, a texture first bound to {{KW|_GL_TEXTURE_1D_ARRAY}} becomes one-dimensional array texture, a texture first bound to {{KW|_GL_TEXTURE_2D_ARRAY}} becomes two-dimensional arary texture, a texture first bound to {{KW|_GL_TEXTURE_RECTANGLE}} becomes rectangle texture, a, texture first bound to {{KW|_GL_TEXTURE_CUBE_MAP}} becomes a cube-mapped texture, a texture first bound to {{KW|_GL_TEXTURE_2D_MULTISAMPLE}} becomes a two-dimensional multisampled texture, and a texture first bound to {{KW|_GL_TEXTURE_2D_MULTISAMPLE_ARRAY}} becomes a two-dimensional multisampled array texture. The state of a one-dimensional texture immediately after it is first bound is equivalent to the state of the default {{KW|_GL_TEXTURE_1D}} at GL initialization, and similarly for the other texture types.
While a texture is bound, GL operations on the target to which it is bound affect the bound texture, and queries of the target to which it is bound return state from the bound texture. In effect, the texture targets become aliases for the textures currently bound to them, and the texture name zero refers to the default textures that were bound to them at initialization.
A texture binding created with '''_glBindTexture''' remains active until a different texture is bound to the same target, or until the bound texture is deleted with {{KW|_glDeleteTextures}}.
Once created, a named texture may be re-bound to its same original target as often as needed. It is usually much faster to use '''_glBindTexture''' to bind an existing named texture to one of the texture targets than it is to reload the texture image using {{KW|_glTexImage1D}}, {{KW|_glTexImage2D}}, {{KW|_glTexImage3D}} or another similar function.
{{PageNotes}}
The {{KW|_GL_TEXTURE_2D_MULTISAMPLE}} and {{KW|_GL_TEXTURE_2D_MULTISAMPLE_ARRAY}} targets are available only if the GL version is 3.2 or higher.
{{PageErrors}}
{{KW|_GL_INVALID_ENUM}} is generated if {{Parameter|target}} is not one of the allowable values.
{{KW|_GL_INVALID_VALUE}} is generated if {{Parameter|target}} is not a name returned from a previous call to {{KW|_glGenTextures}}.
{{KW|_GL_INVALID_OPERATION}} is generated if {{Parameter|texture}} was previously created with a target that doesn't match that of {{Parameter|target}}.
{{PageUseWith}}
{{KW|_glGet}} with argument {{KW|_GL_TEXTURE_BINDING_1D}}, {{KW|_GL_TEXTURE_BINDING_2D}}, {{KW|_GL_TEXTURE_BINDING_3D}}, {{KW|_GL_TEXTURE_BINDING_1D_ARRAY}}, {{KW|_GL_TEXTURE_BINDING_2D_ARRAY}}, {{KW|_GL_TEXTURE_BINDING_RECTANGLE}}, {{KW|_GL_TEXTURE_BINDING_2D_MULTISAMPLE}}, or {{KW|_GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY}}.


{{PageSeeAlso}}
{{PageSeeAlso}}
 
* [[_GL|SUB _GL]]
[[_GL|SUB _GL]]
* [[_glAreTexturesResident]], [[_glDeleteTextures]], [[_glGenTextures]], [https://learn.microsoft.com/en-us/windows/win32/opengl/glgetbooleanv--glgetdoublev--glgetfloatv--glgetintegerv _glGet]
{{KW|_glActiveTexture}}, {{KW|_glDeleteTextures}}, {{KW|_glGenTextures}}, {{KW|_glGetTexParameter}}, {{KW|_glIsTexture}}, {{KW|_glTexParameter}}
* [https://learn.microsoft.com/en-us/windows/win32/opengl/glgettexparameter _glGetTexParameter], [[_glIsTexture]], [[_glPrioritizeTextures]], [[_glTexImage1D]]
* [[_glTexImage2D]], [https://learn.microsoft.com/en-us/windows/win32/opengl/gltexparameter-functions _glTexParameter]




{{PageCopyright}}
{{PageNavigation}}

Latest revision as of 00:35, 28 January 2023

The _glBindTexture statement enables the creation of a named texture that is bound to a texture target.


Syntax

_glBindTexture GLenum target, GLuint texture


Parameters

  • OpenGL is using its own set of variable types to describe its command parameters.
  • Use the following table to find the respective QB64 Variable Types.
   Table 2: Relations between the OpenGL variable types vs. C/C++ and QB64.
 ┌──────────────┬────────────────┬──────────────────────────────────────────┐
 │    OpenGLC/C++QB64                                 │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLenum       │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLboolean    │ unsigned char  │ _UNSIGNED _BYTE                          │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLbitfield   │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLbyte       │ signed char    │ _BYTE                                    │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLshort      │ short          │ INTEGER                                  │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLint        │ int            │ LONG                                     │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLsizei      │ int            │ LONG                                     │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLubyte      │ unsigned char  │ _UNSIGNED _BYTE                          │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLushort     │ unsigned short │ _UNSIGNED INTEGER                        │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLuint       │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLfloat      │ float          │ SINGLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLclampf     │ float          │ SINGLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLdouble     │ double         │ DOUBLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLclampd     │ double         │ DOUBLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLvoid   (1) │ void           │ _OFFSET(any fixed lenght string or _BYTE │
 │              │                │         array element)                   │
 └──────────────┴────────────────┴──────────────────────────────────────────┘
 Note: If a parameter has an asterisk (*) in front, then it's a pointer to
       the designated OpenGL variable type, rather than a value of that type.
       Those must be passed using the _OFFSET(...) notation.

 E.g.  GLuint *anyParam is actually the offset of a _UNSIGNED LONG (~&)
       variable or array, which must be passed as _OFFSET(anyVar~&) or
       _OFFSET(anyArr~&()) respectively.

  (1)  This type is regularly only used for pointers (with asterisk (*)) to
       any byte sized memory data, hence _BYTE or fixed length strings.


Description

  • OpenGL's documentation is available in several places, so we won't reproduce it here for another time.
  • The full description for this command can be found at Microsoft Docs and is also valid for QB64 usage.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link