• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 29  文章 - 13  trackbacks - 0
            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            相冊

            收藏夾

            c++

            Linux

            Tools

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            TextureApp2.JPG


            點此下載源文件

            /*
            MainApp.hpp
            */
            #ifndef MAINAPP_HPP
            #define MAINAPP_HPP
            #include <GL/gl.h>
            #include <SDL/SDL.h>

            #define ImageWidth 64
            #define ImageHeight 64

            class MainApp
            {
            public:
            ??? MainApp();
            ??? ~MainApp();
            ??? void loop();???
            ??? void quit();???
            ???
            private:???
            ??? void initGL();
            ??? void initTexture();
            ??? void makeImage();
            ??? void destroyGL();
            ??? void onKeyDown(const SDL_Event &event);
            ??? void draw();
            ??? bool running;
            ??? GLubyte Image[ImageWidth][ImageHeight][3];
            };

            #endif


            /*
            MainApp.cpp
            */
            #include <GL/gl.h>
            #include <SDL/SDL.h>
            #include "MainApp.hpp"

            MainApp::MainApp():running(true)
            {
            ?? ?initGL();
            }
            MainApp::~MainApp()
            {
            ?? ?destroyGL();
            }

            void MainApp::initGL()
            {
            ?? ?SDL_Init(SDL_INIT_VIDEO);
            ?? ?SDL_SetVideoMode(600,300,16,SDL_OPENGL);
            ?? ?glClearColor(0,0,0,0);
            ?? ?initTexture();
            }

            /* 創建紋理 */
            void MainApp::makeImage(void)
            {
            ??? int i, j, r,g,b;
            ??? for (i = 0; i < ImageWidth; i++)
            ?? ?{
            ?? ??? ?for (j = 0; j < ImageHeight; j++)
            ?? ??? ?{
            ?? ??????? r=(i*j)%255;
            ?? ??? ???? g=(4*i)%255;
            ?????? ??? ?b=(4*j)%255;
            ?? ???????? Image[i][j][0] = (GLubyte) r;
            ?????? ??? ?Image[i][j][1] = (GLubyte) g;
            ?? ??? ???? Image[i][j][2] = (GLubyte) b;
            ?? ??? ?}
            ??? }
            }

            void MainApp::initTexture()
            {
            ?? ?makeImage();
            ?/*? 定義紋理 */
            ??? glTexImage2D(GL_TEXTURE_2D, 0, 3, ImageWidth,
            ??? ImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
            ??? &Image[0][0][0]);
            ? /*? 控制濾波 */
            ??? glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
            ?? glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
            ??? glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            ??? glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            /*? 說明映射方式*/
            ?? glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
            /*? 啟動紋理映射 */
            ??? glEnable(GL_TEXTURE_2D);
            }

            void MainApp::destroyGL()
            {
            ?? ?SDL_Quit();
            }
            void MainApp::loop()
            {
            ?? ?SDL_Event event;
            ?? ?while(running)
            ?? ?{
            ?? ??? ?while(SDL_PollEvent(&event))
            ?? ??? ?{
            ?? ??? ??? ?switch(event.type)
            ?? ??? ??? ?{
            ?? ??? ??? ?case SDL_KEYDOWN:
            ?? ??? ??? ??? ?onKeyDown(event);
            ?? ??? ??? ??? ?break;
            ?? ??? ??? ?}
            ?? ??? ?}
            ?? ??? ?SDL_Delay(50);
            ?? ??? ?draw();
            ?? ?}
            }
            void MainApp::quit()
            {
            ?? ?running=false;
            }
            void MainApp::onKeyDown(const SDL_Event &event)
            {
            ?? ?switch(event.key.keysym.sym)
            ?? ?{
            ?? ?case SDLK_ESCAPE:
            ?? ??? ?quit();
            ?? ?}
            }
            void MainApp::draw()
            {
            ?? ?glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
            ?? ?glBegin(GL_QUADS);
            ?? ??? ?glColor3f(1,1,1);
            ?? ??? ?glTexCoord2f(0,0);glVertex3f(-0.5,-0.5,-0.5);
            ?? ??? ?glTexCoord2f(0,1);glVertex3f(-0.5,0.5,-0.5);
            ?? ??? ?glTexCoord2f(1,1);glVertex3f(0.5,0.5,0.5);
            ?? ??? ?glTexCoord2f(1,0);glVertex3f(0.5,-0.5,0.5);
            ?? ?glEnd();
            ?? ?
            ?? ?SDL_GL_SwapBuffers();
            }

            int main(int argc,char* argv[])
            {
            ?? ?MainApp app;
            ?? ?app.loop();?? ?
            }

            posted on 2006-10-17 18:42 四海 閱讀(1419) 評論(0)  編輯 收藏 引用
            女同久久| 久久综合狠狠综合久久97色| 久久午夜免费视频| 国产精品久久久久久| 伊人伊成久久人综合网777| 久久国产亚洲精品无码| 污污内射久久一区二区欧美日韩 | 久久亚洲国产成人精品性色| 久久国产成人| 99久久精品费精品国产| 久久国产亚洲精品麻豆| 久久国产精品无码一区二区三区| 青草影院天堂男人久久| 日本免费久久久久久久网站| 亚洲精品国产第一综合99久久 | 中文字幕无码av激情不卡久久| av无码久久久久久不卡网站| 亚洲香蕉网久久综合影视| 亚洲精品乱码久久久久久| 日本强好片久久久久久AAA| 久久综合色区| 99久久精品国产一区二区蜜芽| 国内精品九九久久精品| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久久精品国产亚洲成人满18免费网站| 亚洲国产精品热久久| 久久午夜福利无码1000合集| 久久午夜伦鲁片免费无码| 综合久久给合久久狠狠狠97色| 成人午夜精品久久久久久久小说 | 国内精品久久久久久久久电影网 | 无码AV波多野结衣久久| 久久久久久亚洲精品影院| 亚洲国产精品成人久久蜜臀| 久久久久久无码国产精品中文字幕| 国产ww久久久久久久久久| 久久久久久狠狠丁香| 国产日韩久久久精品影院首页| 精品视频久久久久| 亚洲精品tv久久久久| 久久精品国产乱子伦|