2019年3月29日 星期五

幫我稱10秒!!_week06

先下載[source][data][win32glut32.dll 

打開source的資料夾,用notepad++開啟lightmaterial.c
搜尋關鍵字glm 把有相關的程式丟入上周的茶壺code block程式
有下列這幾個
#include "glm.h"

GLMmodel* pmodel = NULL;

if (!pmodel) { pmodel = glmReadOBJ("data/soccerball.obj"); if (!pmodel) exit(0); glmUnitize(pmodel); glmFacetNormals(pmodel); glmVertexNormals(pmodel, 90.0); } glmDraw(pmodel, GLM_SMOOTH);


把glm.h 和glm.c丟進code block的資料夾裡
glm.c改名成glm.cpp
資料夾內容如下


再從code block新增glm.cpp的檔案

最後把date資料夾丟入freeglut資料夾的bin資料夾裡

最終程式:
#include <GL/glut.h> #include "glm.h" GLMmodel* pmodel = NULL; //以下程式控制顏色 const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.1f, 1.0f }; const GLfloat light_diffuse[] = { 0.0f, 1.0f, 1.0f, 1.0f }; const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; const GLfloat light_position[] = { -2.0f, 2.0f, 2.0f, 1.0f }; const GLfloat mat_ambient[] = { 0.17f, 0.01f, 0.01f, 0.55f }; const GLfloat mat_diffuse[] = { 0.61f, 0.04f, 0.04f, 0.55f }; const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; const GLfloat high_shininess[] = { 77.0f }; //以上 float angle=0; void display() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if (!pmodel) { pmodel = glmReadOBJ("data/soccerball.obj"); if (!pmodel) exit(0); glmUnitize(pmodel); glmFacetNormals(pmodel); glmVertexNormals(pmodel, 90.0); }

glmDraw(pmodel, GLM_SMOOTH|GLM_MATERIAL); glutSwapBuffers(); } int main(int argc,char ** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); glutCreateWindow("第N個程式"); glutDisplayFunc(display); glClearColor(1,1,1,1);//背景顏色 glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); glutMainLoop(); }


會出maya模型 file-->export selection 檔案類型選obj




貼上有顏色的程式碼
1.將所有程式碼全選貼到notepad++
2.檔案存成.cpp檔
3.外掛-->NppexPort-->Export to HTML-->用google開啟

沒有留言:

張貼留言