OpenGL繪製茶壺 光照 變換

2021-09-28 15:52:32 字數 2914 閱讀 4571

本文致謝brother teeth.

時間緊,不多寫了,直接看注釋。

#include #include #include#include#include "gl\gl.h"

#include "gl\glu.h"

#include "gl\glaux.h"

#include "gl\glut.h"

bool pause;

bool light;

const float pi = 3.1415926;

int xangle;//x軸向角度

int yangle;//y軸向角度

float xradian;//x軸向弧度

float yradian;//y軸向弧度

float distance;//間距

int rotatespeedsleep;//旋轉速度

glfloat lightambient = ; // 環境光引數

glfloat lightdiffuse = ; // 漫射光引數

glfloat lightposition = ; // 光源位置

gluint filter; // 濾波型別

gluint texture[3]; // 3種紋理的儲存空間

glfloat rx, ry, rz; // 物體 旋轉

gldouble size; // 物體尺寸

glfloat ox = 0.0f, oy = 0.0f, oz = 0.0f; //物體位置

glfloat cx = 0.0f, cy = 0.0f, cz = 5.0f;//攝像機位置

glfloat cvx = 0.0f, cvy = 0.0f, cvz = -1.0f;//攝像機視線向量

glfloat chx = 0.0f, chy = 1.0f, chz = 0.0f;//攝像機頭頂朝向向量

glfloat w_h_ratio;//長寬比

void variateinit()

// 載入位圖圖象

aux_rgbimagerec* loadbmp(char* filename)

int errnum = fopen_s(&file,filename, "r"); // 嘗試開啟檔案

if (file) // 檔案存在麼?

return null; // 如果載入失敗,返回 null

}// 載入位圖(呼叫上面的**)並轉換成紋理

int loadgltextures()

if (textureimage[0]) // 紋理是否存在

free(textureimage[0]); // 釋放影象結構

} return status; // 返回 status

}// 初始化opengl設定

int myinit(glvoid)

glenable(gl_texture_2d); // 啟用紋理對映

glshademodel(gl_smooth); // 啟用陰影平滑

glclearcolor(0.0f, 0.0f, 0.0f, 0.5f); // 黑色背景

glcleardepth(1.0f); // 設定深度快取

glenable(gl_depth_test); // 啟用深度測試

gldepthfunc(gl_lequal); // 所作深度測試的型別

glhint(gl_perspective_correction_hint, gl_nicest); // 真正精細的透視修正

gllightfv(gl_light0, gl_ambient, lightambient); // 設定環境光

gllightfv(gl_light0, gl_diffuse, lightdiffuse); // 設定漫射光

gllightfv(gl_light0, gl_position, lightposition); // 設定光源位置

glenable(gl_light0); // 啟用0號光源

glenable(gl_lighting);

glenable(gl_depth_test);

glcolor4f(1.0f, 1.0f, 1.0f, 0.5f); // 全亮度, 50% alpha 混合

glblendfunc(gl_src_alpha, gl_one); // 基於源象素alpha通道值的半透明混合函式

return true; // 初始化 ok

}void drawteapot(void)

void mydisplay(void)

void rotatecamera(int x, int y)

void movecamera(int x, int y, int z)

//燈光 控制

Opengl光照(茶壺)

include initialize material property,light source,lighting model,and depth buffer.void init void glfloat mat shininess glfloat light position glfloat ...

OpenGL入門學習二 繪製旋轉的茶壺

from opengl.gl import from opengl.glut import from opengl.glu import def drawfunc 清空之前畫面 glclear gl color buffer bit 旋轉,引數為 旋轉角度 xyz軸的布林值變數。表示繞哪些軸旋轉 g...

openGL光照系統

opengl 把光照系統分成了三部分 光源,材質和光照環境。opengl 沒有考慮光的折射 1.控制光源 第乙個引數表示設定哪乙個光源的屬性,第二個引數表示設定這個光源的哪個屬性,第三個引數則表示把該屬性值設定為多少 gllightfv gl light0,gl position,sun light...