Skip to content
Search

GlGenTextures

lastmod 2024-08-18created 2021-05-082 edits

glGenTextures — generate texture names.

C Specification

void glGenTextures(GLsizei n, GLuint * textures);

Parameters:

  • n: Specifies the number of texture names to be generated.
  • textures: Specifies an array in which the generated texture names are stored.

Description

glGenTextures returns n texture names in textures. There is no guarantee that the names form a contiguous set of integers; however, it is guaranteed that none of the returned names was in use immediately before the call to glGenTextures. The generated textures have no dimensionality; they assume the dimensionality of the texture target to which they are first bound (see glBindTexture). Texture names returned by a call to glGenTextures are not returned by subsequent calls, unless they are first deleted with glDeleteTextures.

Example

Generates textures.

GLAPI void GLAPIENTRY glGenTextures (
    GLsizei n, // 생성할 텍스쳐 갯수.
    GLuint *textures // 텍스처에 접근할 인덱스를 받을 변수의 주소값.
);

// ...

// 텍스처를 3개 만들겠다.
GLuint tex[3];
glGenTextures( 3, tex );

// ...

// 1개를 만들겠다.
GLuing tex;
glGenTextures( 1, &tex );

Buffer objects, fast texture loading

How to load textures through OpenGL buffer objects. Naturally, this is a must if you want fast loading.

Textures are sent up to video memory in the following steps

Storage -load via buffer-> video memory. Storage is the space data is loaded from: the web, a hard disk, and various others

I'll explain one step at a time with reference to the functions. OpenGL initialization objects are omitted (they differ by platform... using a framework such as glu, glx, etc. makes it much easier)

Creating buffers/textures

C++

GLenum buffer[2],texture[2]; glGenBuffers(2, &buffer[0]);
glGenTextures(2, &texture[0]);

Pascal

var buffer,texture: array [0..1] of GLenum; glGenBuffers(2, @buffer[0]);
glGenTextures(2, @texture[0]);

Bind the GL buffer object as a pixel buffer and create it (192010803: RGB channels at 1080p), (STATIC: edit once, use many times; DYNAMIC: edit many times, use many times)

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer[0]);
glBufferData(GL_PIXEL_UNPACK_BUFFER,1920*1080*3, nil, GL_STATIC_DRAW);

Map the video memory into system virtual memory

// 메모리포인터 := glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
FillMemory(메모리포인터,1920*1080*2,127);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);

Pull the buffer's data into the texture: bind the texture as GL_TEXTURE_2D, set the texture parameters, and attach the data from the buffer

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, 1920, 1080, 0, GL_RGB, GL_UNSIGNED_BYTE, nil);

This is also called a PBO (Pixel Buffer Object), and that's all there is to it. There are also vertex buffers and texture buffers. Related functions: glGetBufferSubData, glGetTexImage (functions that read back buffer and texture data; for other functions, search Google for "glFunctionName wiki")

See also

Favorite site

author Zer0 sitemap