VR Open GL 2 D imagepixelcolor Open GL

  • Slides: 27
Download presentation
VR – Open. GL 2 D

VR – Open. GL 2 D

大綱 image、pixel和color基本概念 Open. GL 2 D functions 繪圖流程和相關Library 遊戲和輸入控制 參考資料 Demo

大綱 image、pixel和color基本概念 Open. GL 2 D functions 繪圖流程和相關Library 遊戲和輸入控制 參考資料 Demo

image、pixel和color 基本概念

image、pixel和color 基本概念

BMP image Image:可看成一維Pixel Array, 每個Pixel由RGB組成,共 24 bit Pixel的其他表示法 lookup table

BMP image Image:可看成一維Pixel Array, 每個Pixel由RGB組成,共 24 bit Pixel的其他表示法 lookup table

Open. GL 2 D function

Open. GL 2 D function

Positioning Image Primitives gl. Raster. Pos 3 f( x, y, z ) n n

Positioning Image Primitives gl. Raster. Pos 3 f( x, y, z ) n n raster position transformed like geometry 若超過viewport的邊界 會被忽略 w may need to fine tune viewport for desired results Raster Position X ->

Open. GL raster display draw framebuffer memory copy read gl. Read. Pixels(); gl. Copy.

Open. GL raster display draw framebuffer memory copy read gl. Read. Pixels(); gl. Copy. Pixels(); gl. Draw. Pixels()

Rendering Images gl. Draw. Pixels( width, height, format, type, pixels ) n n render

Rendering Images gl. Draw. Pixels( width, height, format, type, pixels ) n n render pixels with lower left of image at current raster position numerous formats and data types for specifying storage in memory w best performance by using format and type that matches hardware

Reading Pixels gl. Read. Pixels( x, y, width, height, format, type, pixels ) n

Reading Pixels gl. Read. Pixels( x, y, width, height, format, type, pixels ) n n read pixels from specified (x, y) position in framebuffer pixels automatically converted from framebuffer format into requested format and type Framebuffer pixel copy gl. Copy. Pixels( x, y, width, height, type ) copy pixels in the frame buffer to current raster position

放大縮小 gl. Pixel. Zoom() gl. Pixel. Zoom(水平軸倍數, 垂直軸倍數) Ex: gl. Pixel. Zoom(1. 0, 1.

放大縮小 gl. Pixel. Zoom() gl. Pixel. Zoom(水平軸倍數, 垂直軸倍數) Ex: gl. Pixel. Zoom(1. 0, 1. 0); //不變 gl. Pixel. Zoom(2. 0, 2. 0); //放大兩倍 gl. Pixel. Zoom(0. 5, 0. 5); //縮小 gl. Pixel. Zoom(-1. 0, 1. 0); //水平反轉

RGBpixmap. h #include "RGBpixmap. h“ RGBpixmap pic; //宣告一張背景圖 //讀檔 pic. read. BMPFile(“background. bmp”); 讀取的必須是

RGBpixmap. h #include "RGBpixmap. h“ RGBpixmap pic; //宣告一張背景圖 //讀檔 pic. read. BMPFile(“background. bmp”); 讀取的必須是 24 bit的bmp檔 pic. n. Rows //int 列數 pic. n. Cols //int 行數 pic. draw() //繪圖

繪圖基本流程 void my. Display(void) { gl. Clear(GL_COLOR_BUFFER_BIT); gl. Raster. Pos 2 i(0, 0); //繪圖的左下角

繪圖基本流程 void my. Display(void) { gl. Clear(GL_COLOR_BUFFER_BIT); gl. Raster. Pos 2 i(0, 0); //繪圖的左下角 pic. draw(); //繪圖 glut. Swap. Buffers(); }

字型設定 font. h GLFONT *Font; //宣告 GLFONT *Font. Create(HDC hdc, const char *typeface, int

字型設定 font. h GLFONT *Font; //宣告 GLFONT *Font. Create(HDC hdc, const char *typeface, int height, int weight, DWORD italic); typeface 字形名稱 height 字形高度 weight 粗體設定 italic 斜體設定 Ex: Font = Font. Create(wgl. Get. Current. DC(), "Times", 32, 0, 1);

字型顯示 font. h #include <string. h> //for sprintf(); 在display()內 char mss[30]; sprintf(mss, "Score %d",

字型顯示 font. h #include <string. h> //for sprintf(); 在display()內 char mss[30]; sprintf(mss, "Score %d", Gamescore); gl. Color 3 f(1. 0, 0. 0); //設定字型顏色 gl. Raster. Pos 2 i(10, 450); //設定字型左下角起點 Font. Printf(Font, 1, mss);

利用鍵盤輸入使圖片移動 在Speckeyfunc() switch(key) { case GLUT_KEY_LEFT: pic. X -= 5; break; case GLUT_KEY_RIGHT: pic.

利用鍵盤輸入使圖片移動 在Speckeyfunc() switch(key) { case GLUT_KEY_LEFT: pic. X -= 5; break; case GLUT_KEY_RIGHT: pic. X += 5; break; ……. . } glut. Post. Redisplay(); RGBApixmap pic[3]; 在Display() gl. Raster. Pos 2 i(pic. X, pic. Y); pic[which. Pic]. blend();

換圖 在Speckeyfunc() case GLUT_KEY_LEFT: pic. X -= 5; if (which. Pic==0) which. Pic=1; else

換圖 在Speckeyfunc() case GLUT_KEY_LEFT: pic. X -= 5; if (which. Pic==0) which. Pic=1; else which. Pic=0; break; case GLUT_KEY_RIGHT: pic. X += 5; if (which. Pic==0) which. Pic=1; else which. Pic=0; break; 0 1

轉方向 int Direct. State=0; 在Speckeyfunc() case GLUT_KEY_LEFT: pic. X -= 5; which. Pic=1; if

轉方向 int Direct. State=0; 在Speckeyfunc() case GLUT_KEY_LEFT: pic. X -= 5; which. Pic=1; if (which. Pic==0) else which. Pic=0; Direct. State=1; break; case GLUT_KEY_RIGHT: …… Direct. State=0; break; 在Display() if(Direct. State==0) { gl. Pixel. Zoom(1. 0, 1. 0); gl. Raster. Pos 2 i(pic. X, pic. Y); }else { gl. Pixel. Zoom(-1. 0, 1. 0); gl. Raster. Pos 2 i(pic. X+pic[which. P ic]. n. Cols, pic. Y); } pic[which. Pic]. blend();

glut. Timer. Func() glut. Timer. Func(int msecs, (*func)(int value), int value); 登記一個func,在經過msecs毫秒後呼叫,並將 value值設給func Func的宣告

glut. Timer. Func() glut. Timer. Func(int msecs, (*func)(int value), int value); 登記一個func,在經過msecs毫秒後呼叫,並將 value值設給func Func的宣告 void jump(int i);

How to use time funtion void jump(int i) { which. Pic=2; //切換到jump圖片 if (i<5)

How to use time funtion void jump(int i) { which. Pic=2; //切換到jump圖片 if (i<5) pic. Y+=4; //前五次向上移 else pic. Y-=4; //後幾次向下移 if(i<10) { i++; glut. Timer. Func( 100, jump, i); //呼叫time fution }else { which. Pic=0; //回復原先狀態 jump. State=0; } glut. Post. Redisplay(); } 2

Jump-keyfuntion case 'm': if(jump. State==0) { jump. State=1; Gamescore++; jump(0); } break;

Jump-keyfuntion case 'm': if(jump. State==0) { jump. State=1; Gamescore++; jump(0); } break;

參考資料 GLUT 使用說明 用google查glut game第 一個連結 Open. GL 超級手冊 Ch 7 Open. GL Programming

參考資料 GLUT 使用說明 用google查glut game第 一個連結 Open. GL 超級手冊 Ch 7 Open. GL Programming Guide Ch 8 http: //ask. ii. uib. no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/Open. GL_PG Open. GL官方網站Http: //www. opengl. org