游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3010|回复: 2

用openGL做纹理贴图问题

[复制链接]

2

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2009-4-10 09:00:00 | 显示全部楼层 |阅读模式
最近做毕业设计,老师让我接受前面一个研究生的工作,他做的是基于iPhone的骨骼动画,用openGL实现。老师让我接手他的程序做纹理贴图,我拿到代码不知从何入手,以前没有任何经验,请各位高手指点下,我把整个代码发下面,希望大家指点下我要改哪些地方,我再自己研究。各位多多帮忙哈,做不出就比不了业啦!!
/*
*  template.mm
*  template
*
*  Created by SIO2 Interactive on 8/22/08.
*  Copyright 2008 SIO2 Interactive. All rights reserved.
*
*/

#include "template.h"
#include "../src/sio2/sio2.h"
#import "data.h"
#import "bmpload.h"

xData xDataModel;

TEXTUREIMAGE bmptexture;


void templateRender( void )
{
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();

        glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

        SIO2camera *_SIO2camera = ( SIO2camera * )sio2ResourceGet( sio2->_SIO2resource,
                                                                                                                           SIO2_CAMERA,
                                                                                                                           "camera/Camera" );

        if( _SIO2camera )
        {
                sio2CameraSetPerspective( _SIO2camera, sio2->_SIO2window );
               
                sio2WindowEnterLandscape3D();
                {
                        sio2CameraRender( _SIO2camera );
                       
                        sio2ResourceRender( sio2->_SIO2resource,
                                                           sio2->_SIO2window,
                                                                _SIO2camera,
                                                                SIO2_RENDER_SOLID_OBJECT );
                       
                        //====================================================================
                        //glColor4f(0.5,0.6,0.8,1.0);
                       
                        xDataModel.advanceAnimation(0);
                        xDataModel.updateFrame(&xDataModel.pRootFrame);
                        xDataModel.updateSkinedMesh(xDataModel.pRootFrame);
                       
                        GLuint tex_handle;
                        glGenTextures(1, &tex_handle);
                        glBindTexture(GL_TEXTURE_2D, tex_handle);
                        glTexImage2D(GL_TEXTURE_2D,
                                                 0,
                                                 GL_RGB,
                                                 bmptexture.imgWidth,
                                                 bmptexture.imgHeight,
                                                 0,
                                                 GL_RGB,
                                                 GL_UNSIGNED_BYTE,
                                                 bmptexture.data);       
                        glEnable(GL_TEXTURE_2D);
                        glBindTexture(GL_TEXTURE_2D, tex_handle);
                       
                        xDataModel.Render();
                       
                        glDisable(GL_TEXTURE_2D);
                        glDeleteTextures(1,&tex_handle);

                       
                        xDataModel.Render();
                       
                        glDisable(GL_TEXTURE_2D);
                        glDeleteTextures(1,&tex_handle);
                }
                sio2WindowLeaveLandscape3D();
        }
}


void templateShutdown( void )
{
        sio2ResourceUnloadAll( sio2->_SIO2resource );

        sio2->_SIO2window = sio2WindowFree( sio2->_SIO2window );
               
        sio2->_SIO2resource = sio2ResourceFree( sio2->_SIO2resource );

        sio2 = sio2Shutdown();

        printf("\nSIO2: shutdown...\n" );
}


void templateLoading( void )
{
        unsigned int i = 0;
       
        sio2ResourceCreateDictionary( sio2->_SIO2resource );
       
        sio2ResourceOpen( sio2->_SIO2resource,
                                          "tutorial03.sio2", 1 );
       
        while( i != sio2->_SIO2resource->gi.number_entry )
        {
                sio2ResourceExtract( sio2->_SIO2resource );
                ++i;
        }

        sio2ResourceClose( sio2->_SIO2resource );

        /*
                SIO2 support natively the following image format:
               
                JPEG 24bits (RGB)                                 = Need decompression but no byte swap
                JPEG  8bits (LUMINANCE)                         = Need decompression but no byte swap
               
                RAW TGA 24bits (RGB)                     = Need to swap BGR to RGB
                RAW TGA 32bits (BGRA)                     = Fast, no decompression or byte swap
                RAW TGA 16bits (LUMINANCE_ALPHA) = Fast, no decompression or byte swap
                RAW TGA  8bits (LUMINANCE)             = Fast, no decompression or byte swap
               
                RLE TGA 24bits(RGB)                                 = Need decompression + byte swap ( BGR -> RGB )
                RLE TGA 32bits(BGRA)                         = Need decompression but no byte swap
                RLE TGA 16bits (LUMINANCE_ALPHA) = Need decompression but no byte swap
                RLE TGA  8bits(LUMINANCE)                 = Need decompression but no byte swap
               
                PNG        24bits (RGB)                                 = Need decompression but no byte swap + need flip
                PNG 32bits (RGBA)                                 = Need decompression + byte swap ( RGBA -> BGRA ) + need flip
                PNG 16bits (LUMINANCE_ALPHA)         = Need decompression but no byte swap + need flip
                PNG  8bits (LUMINANCE)                         = Need decompression but no byte swap + need flip
                PNG Palette                                                 = Fast decompression ( Same for 24/32/16/8 bits )
                               
                Please take note that also due to the TGA file format some image
                have to be flipped on the Y axis, to avoid flipping save your TGA
                with the origin as the top left corner instead of bottom left,
                they would load faster cuz no flipping is required.
               
                ps: If flipping is required, it is done internally so no need to worry about it.
               
                The following command wil bind all the different
                images to all the materials currently held in the
                library.               
        */
        sio2ResourceBindAllImages( sio2->_SIO2resource );


        /*
                The following command wil bind all the different
                materials to all the objects currently held in the
                library.
        */
        sio2ResourceBindAllMaterials( sio2->_SIO2resource );

        sio2ResourceBindAllMatrix( sio2->_SIO2resource );
       
        // Generate all the VBO and OpenGL texture ID.
        sio2ResourceGenId( sio2->_SIO2resource );

        // Reset all resource state pointer.
        sio2ResourceResetState();

        sio2->_SIO2window->_SIO2windowrender = templateRender;
       
        int k=xDataModel.createData("/Users/shushu/desktop/jason/SIO2_SDK_v1.3.3/tutorial03/media/g.x");
        printf("%d\n",k);
        xDataModel.PrepareRender();
       
        char *fname="/Users/shushu/desktop/jason/SIO2_SDK_v1.3.3/tutorial03/media/dbc-jsbc003.bmp";
        int s=LoadBmp(fname, &bmptexture);       
        printf("/n width:%d,height:%d,/n",bmptexture.imgWidth,bmptexture.imgHeight);
}


void templateScreenTap( void *_ptr, unsigned char _state )
{

}


void templateScreenTouchMove( void *_ptr )
{

}


void templateScreenAccelerometer( void *_ptr )
{

}

abcabcabcabc

5

主题

68

帖子

90

积分

注册会员

Rank: 2

积分
90
QQ
发表于 2009-4-11 16:45:00 | 显示全部楼层

Re:用openGL做纹理贴图问题

他做的是基于iPhone的骨骼动画,用openGL实现。。。我晕什么学校呀 还写 iphone 蒙了~

2

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2009-4-12 12:45:00 | 显示全部楼层

Re:用openGL做纹理贴图问题

是啊,我现在只有先自学openGL了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-20 14:12

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表