NVIDIA SDK 9.5 Simple Texture Rectangle

NVIDIA SDK 9.5 Simple Texture Rectangle

缘起:
为看这个做知识储备,因为OpenGL不熟悉
玩玩DirectShow--(2) NVIDIA SDK 9.5 GPU Video Effects

截图:
NVIDIA SDK 9.5 Simple Texture Rectangle_第1张图片
核心代码:

         渲染

void  display()
{
    glClear(GL_COLOR_BUFFER_BIT 
|  GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    camera.apply_inverse_transform();

    
object .apply_transform();
    glRotatef(
60.0f - 1.0f 1.0f 0.0f  );

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, tex.texture);
    glEnable(GL_TEXTURE_RECTANGLE_NV);

    quad.call_list();

    
    glPopMatrix();

    glutSwapBuffers();
}

         初始化
void  init_opengl()
{
    
if  ( ! glh_extension_supported( " GL_EXT_texture_rectangle " &&  
        
! glh_extension_supported( " GL_NV_texture_rectangle " ))
    {
    cerr 
<<   " Video card does not support texture rectangles "   <<  endl;
        quitapp(
0 );
    }

   
    glEnable(GL_DEPTH_TEST);


    array2
< vec3ub >  img;

    tex.bind();  
//  get a texture name and bind it
    read_png_rgb( " nvlogo_rect.png " , img);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 
1 );
    glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 
0 , GL_RGB, img.get_width(), img.get_height(),  0 ,
                 GL_RGB, GL_UNSIGNED_BYTE, 
&  img( 0 , 0 )[ 0 ]);
                     

    

    
float  aspect  =  img.get_width()  /   float (img.get_height());
    
//  note texture coordinates use image dimensions, not [0,1]
    quad.new_list(GL_COMPILE);
    glPushMatrix();
    
if (aspect  >   1 )
        glScalef(
1 1 / aspect,  1 );
    
else
        glScalef(aspect, 
1 1 );

    glBegin(GL_QUADS);
        glTexCoord2f(
0 0 );
        glVertex3f(
- 1 - 1 0 );

        glTexCoord2f(
0 , img.get_height());
        glVertex3f(
- 1 ,   1 0 );

        glTexCoord2f(img.get_width(), img.get_height());
        glVertex3f( 
1 ,   1 0 );

        glTexCoord2f(img.get_width(), 
0 );
        glVertex3f( 
1 - 1 0 );
    glEnd();

    glPopMatrix();
    quad.end_list();
}

你可能感兴趣的:(NVIDIA SDK 9.5 Simple Texture Rectangle)