void glTexImage2D( GLenum target , GLint level , GLint components , GLsizei width , GLsizei height , GLint border , GLenum format , GLenum type , const GLvoid *pixels );target には、通常 GL_TEXTURE_2D を指定します
| 定数 |
|---|
| GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_ALPHA12, GL_ALPHA16 |
| GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, GL_LUMINANCE12 GL_LUMINANCE16 |
| GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE6_ALPHA2 GL_LUMINANCE8_ALPHA8, GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12 GL_LUMINANCE16_ALPHA16 |
| GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, GL_INTENSITY16 |
| GL_R3_G3_B2, GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, GL_RGB10, GL_RGB12, GL_RGB16 |
| GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1 GL_RGBA8, GL_RGB10_A2, GL_RGBA12, GL_RGBA16 |
void glTexCoord1d(GLdouble s); void glTexCoord1f(GLfloat s); void glTexCoord1i(GLint s); void glTexCoord1s(GLshort s); void glTexCoord2d(GLdouble s, GLdouble t); void glTexCoord2f(GLfloat s, GLfloat t); void glTexCoord2i(GLint s, GLint t); void glTexCoord2s(GLshort s, GLshort t); void glTexCoord3d( GLdouble s, GLdouble t, GLdouble r ); void glTexCoord3f( GLfloat s, GLfloat t, GLfloat r ); void glTexCoord3i( GLint s, GLint t, GLint r ); void glTexCoord3s( GLshort s, GLshort t, GLshort r ); void glTexCoord4d( GLdouble s, GLdouble t, GLdouble r, GLdouble q ); void glTexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q ); void glTexCoord4i( GLint s, GLint t, GLint r, GLint q ); void glTexCoord4s( GLshort s, GLshort t, GLshort r, GLshort q ); void glTexCoord1dv(const GLdouble *v); void glTexCoord1fv(const GLfloat *v); void glTexCoord1iv(const GLint *v); void glTexCoord1sv(const GLshort *v); void glTexCoord2dv(const GLdouble *v); void glTexCoord2fv(const GLfloat *v); void glTexCoord2iv(const GLint *v); void glTexCoord2sv(const GLshort *v); void glTexCoord3dv(const GLdouble *v); void glTexCoord3fv(const GLfloat *v); void glTexCoord3iv(const GLint *v); void glTexCoord3sv(const GLshort *v); void glTexCoord4dv(const GLdouble *v); void glTexCoord4fv(const GLfloat *v); void glTexCoord4iv(const GLint *v); void glTexCoord4sv(const GLshort *v);新しいテクスチャ座標は (s , t , r , q) に配置されます
#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#define TEXSIZE 64
GLubyte bits[TEXSIZE][TEXSIZE][3];
GLuint texName;
void disp( void ) {
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D , texName);
glBegin(GL_POLYGON);
glTexCoord2f(0 , 0); glVertex2f(-0.9 , -0.9);
glTexCoord2f(0 , 1); glVertex2f(-0.9 , 0.9);
glTexCoord2f(1 , 1); glVertex2f(0.9 , 0.9);
glTexCoord2f(1 , 0); glVertex2f(0.9 , -0.9);
glEnd();
glFlush();
}
void timer(int value) {
glRotatef(1 , 0.5 , 1 , 0.25);
glutPostRedisplay();
glutTimerFunc(50 , timer , 0);
}
int main(int argc , char ** argv) {
unsigned int i , j;
for (i = 0 ; i < TEXSIZE ; i++) {
int r = (i * 0xFF) / TEXSIZE;
for (j = 0 ; j < TEXSIZE ; j++) {
bits[i][j][0] = (GLubyte)r;
bits[i][j][1] = (GLubyte)(( j * 0xFF ) / TEXSIZE);
bits[i][j][2] = (GLubyte)~r;
}
}
glutInit(&argc , argv);
glutInitWindowSize(400 , 300);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow("Kitty on your lap");
glutDisplayFunc(disp);
glutTimerFunc(100 , timer , 0);
glEnable(GL_TEXTURE_2D);
glGenTextures(1 , &texName);
glBindTexture(GL_TEXTURE_2D , texName);
glTexImage2D(
GL_TEXTURE_2D , 0 , 3 , TEXSIZE , TEXSIZE ,
0 , GL_RGB , GL_UNSIGNED_BYTE , bits
);
glutMainLoop();
return 0;
}

#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#define TEXSIZE 64
GLubyte bits[TEXSIZE][TEXSIZE][3];
GLuint texName;
void disp( void ) {
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D , texName);
glRotated(2 , 1 , 1 , 0.25);
glBegin(GL_POLYGON);
glTexCoord2f(0 , 0); glVertex2f(-0.9 , -0.9);
glTexCoord2f(0 , 1); glVertex2f(-0.9 , 0.9);
glTexCoord2f(1 , 1); glVertex2f(0.9 , 0.9);
glTexCoord2f(1 , 0); glVertex2f(0.9 , -0.9);
glEnd();
glFlush();
}
void timer(int value) {
glRotatef(1 , 0.5 , 1 , 0.25);
glutPostRedisplay();
glutTimerFunc(50 , timer , 0);
}
int main(int argc , char ** argv) {
unsigned int i , j;
for (i = 0 ; i < TEXSIZE ; i++) {
int r = (i * 0xFF) / TEXSIZE;
for (j = 0 ; j < TEXSIZE ; j++) {
bits[i][j][0] = (GLubyte)r;
bits[i][j][1] = (GLubyte)(( j * 0xFF ) / TEXSIZE);
bits[i][j][2] = (GLubyte)~r;
}
}
glutInit(&argc , argv);
glutInitWindowSize(400 , 300);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow("Kitty on your lap");
glutDisplayFunc(disp);
glutTimerFunc(100 , timer , 0);
glEnable(GL_TEXTURE_2D);
glGenTextures(1 , &texName);
glBindTexture(GL_TEXTURE_2D , texName);
glTexImage2D(
GL_TEXTURE_2D , 0 , 3 , TEXSIZE , TEXSIZE ,
0 , GL_RGB , GL_UNSIGNED_BYTE , bits
);
glutMainLoop();
glDeleteTextures(1 , &texName);
return 0;
}
先ほどのプログラムを改良して、最後にテクスチャの削除を行っています