1. 今天做了一个四面体,并没有处理过锯齿,只是简单的创建了四个三角形(Triangle),这并不难操作,利用以前的框架,再添加上以下代码就可以了~
注意,之前提过的,如果你的屏幕距离四面体过近的话会导致部分会被屏幕裁剪
(If you were to move it only 6 units into the screen, the cube would appear much larger than the pyramid, and parts of it might get cut off by the sides of the screen. You can play around with this setting, and see how moving the triangles further into the screen makes it appear smaller, and moving it closer makes it appear larger. The reason this happens is perspective. Objects in the distance should appear smaller :) )
// this is my first tetrahedron
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -8.0f );
glRotatef( angle = angle >= 360 ? 2 : angle + 2, 1.0f, 1.0f, 0.0f ); glBegin(GL_TRIANGLES);
{
glColor3f( 1.0f, 0.0f, 0.0f );
glVertex3f( 0.0f, 1.0f, 0.0f );
glVertex3f( 0.0f, -1.0f, 1.0f );
glVertex3f( 1.0f, 0.0f, 0.0f );
glColor3f( 0.0f, 1.0f, 0.0f );
glVertex3f( 0.0f, 1.0f, 0.0f );
glVertex3f( 0.0f, -1.0f, 1.0f );
glVertex3f( -1.0f, 0.0f, 0.0f );
glColor3f( 0.0f, 0.0f, 1.0f );
glVertex3f( 0.0f, 1.0f, 0.0f );
glVertex3f( -1.0f, 0.0f, 0.0f );
glVertex3f( 1.0f, 0.0f, 0.0f );
glColor3f( 1.0f, 1.0f, 1.0f );
glVertex3f( 0.0f, -1.0f, 1.0f );
glVertex3f( -1.0f, 0.0f, 0.0f );
glVertex3f( 1.0f, 0.0f, 0.0f );
}
glEnd();
关于立方体的话于此是同理的,我们可以画上六个四边形,就可以了:)
2. glGenTextures(GLsizei, GLuint *) : glGenTextures tells OpenGL we want to generate one texture name (increase the number if you load more than one texture).
3. glBindTexture(GLenum, GLuint) : glBindTexture tells OpenGL to bind the named texture to a texture target. 2D textures have both height (on the Y axes) and width (on the X axes). The main function of glBindTexture is to assign a texture name to texture data.
4. glTexImage2D(GLenum target, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
-
target
-
Specifies the target texture. Must be
GL_TEXTURE_2D.
-
Specifies the level-of-detail number. Level 0 is the base image level. Level
n is the
nth mipmap reduction image.
-
Specifies the number of color components in the texture. Must be 1, 2, 3, or 4.
-
Specifies the width of the texture image. Must be 2^
n + 2 * (
border) for some integer
n.
-
Specifies the height of the texture image. Must be 2^
m + 2 * (
border) for some integer
m.
-
Specifies the width of the border. Must be either 0 or 1.
-
Specifies the format of the pixel data. The following symbolic values are accepted:
GL_COLOR_INDEX,
GL_RED,
GL_GREEN,
GL_BLUE,
GL_ALPHA,
GL_RGB,
GL_RGBA,
GL_LUMINANCE, and
GL_LUMINANCE_ALPHA.
-
Specifies the data type of the pixel data. The following symbolic values are accepted:
GL_UNSIGNED_BYTE,
GL_BYTE,
GL_BITMAP,
GL_UNSIGNED_SHORT,
GL_SHORT,
GL_UNSIGNED_INT,
GL_INT, and
GL_FLOAT.
- Specifies a pointer to the image data in memory.
5. glTexParameteri(GLenum target, GLenum pname, GLfloat param) :
target