Notes for OpenGL - 3

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.

 

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

 

components
Specifies the number of color components in the texture. Must be 1, 2, 3, or 4.

 

width
Specifies the width of the texture image. Must be 2^ n + 2 * ( border) for some integer  n.

 

height
Specifies the height of the texture image. Must be 2^ m + 2 * ( border) for some integer  m.

 

border
Specifies the width of the border. Must be either 0 or 1.

 

format
Specifies the format of the pixel data. The following symbolic values are accepted:  GL_COLOR_INDEXGL_RED, GL_GREENGL_BLUEGL_ALPHAGL_RGBGL_RGBAGL_LUMINANCE, and  GL_LUMINANCE_ALPHA.

 

type
Specifies the data type of the pixel data. The following symbolic values are accepted:  GL_UNSIGNED_BYTE, GL_BYTEGL_BITMAPGL_UNSIGNED_SHORTGL_SHORTGL_UNSIGNED_INTGL_INT, and GL_FLOAT.

 

pixels
Specifies a pointer to the image data in memory.

5. glTexParameteri(GLenum target, GLenum pname, GLfloat param) :

target
Specifies the  target texture, which must be either  GL_TEXTURE_1D, or  GL_TEXTURE_2D.

 

pname
Specifies the symbolic name of a single-valued texture parameter.  pname can be one of the following: GL_TEXTURE_MIN_FILTERGL_TEXTURE_MAG_FILTERGL_TEXTURE_WRAP_S, or GL_TEXTURE_WRAP_T.

 

param
Specifies the value of  pname.   GL_LINEAR ,GL_NEAREST : 
Using GL_LINEAR requires alot of work from the processor/video card, so if your system is slow, you might want to use GL_NEAREST. A texture that's filtered with GL_NEAREST will appear blocky when it's stretched. You can also try a combination of both. Make it filter things up close, but not things in the distance.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值