顯示具有 09163113_蔡鎮洋 標籤的文章。 顯示所有文章
顯示具有 09163113_蔡鎮洋 標籤的文章。 顯示所有文章

2022年3月29日 星期二

啵咕咕的圖學筆記

week06   打光



跟前幾週一樣但這週開啟Light Material.exe

左上可用滑鼠旋轉
右鍵可換模型
左下右鍵換Material

右邊的參數 glLightfv(...)的是float vector(陣列)
glFLOAT LIGHT_POST[]=[-2.0,2.0,2.0,1.0]:陣列
glLightfv(GL_LIGHTO,GL_POSITION.陣列)
                   (第幾個燈)      (設定位置)


freeglut裝好,不刪程式碼ctrl+f 找light偷程式碼
const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.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, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

    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);


#include <GL/glut.h>

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.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, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
..........
int main(int argc, char** argv)

{

    glutInit( &argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week06");
    glutDisplayFunc(display);
    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();

}


將上週程式植入





2022年3月22日 星期二

啵咕咕的圖學筆記week05

 ****電腦圖學之父    Ivan Sutherland*****

如同上週jsyeh.org/3dcg10.....



標準10行

#include <GL/glut.h> 


void display()

{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


    glColor3f(1,1,0); 

    glutSolidTeapot(0.3); 


    glutSwapBuffers();

}


int main(int argc, char** argv) 

{

    glutInit( &argc, argv); 

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH ); 

    glutCreateWindow("week05"); 

    glutDisplayFunc(display); 


    glutMainLoop(); 

}

本週新程式

#include <GL/glut.h>

#include<stdio.h>

void display()

{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


    glColor3f(1,1,0);

    glutSolidTeapot(0.3);


    glutSwapBuffers();

}

void keyboard( unsigned char key,int x,int y)

{

    printf("%c  %d,%d\n",key,x,y);

}

int main(int argc, char** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("week05");

    glutDisplayFunc(display);

    glutKeyboardFunc(keybord);

    glutMainLoop();

}


接續剛剛的

void keyboard( unsigned char key,int x,int y)


{

}

void mouse(int button,int state,int x,int y)

{

}

void motion(int x,int y)

{

}


int main(int argc, char** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("week05");

    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);

    glutMouseFunc(mouse);

    glutMotionFunc(motion);

    glutMainLoop();

}

繼續

#include <GL/glut.h>

#include<stdio.h>

float x=150, y=150, z=0;

int oldX=0, oldY=0;

void display()

{

    glClearColor(0.5,0.5,0.5,1);

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix();

        glTranslatef((x-150)/150.0, -(y-150)/150.0,z);

        glColor3f(1,1,0);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

void keyboard( unsigned char key,int x,int y)

{

}

void mouse(int button,int state,int mouseX,int mouseY)

{

    oldX=mouseX; oldY=mouseY;

}

void motion(int mouseX,int mouseY)

{


    x += (mouseX-oldX); y +=(mouseY-oldY);

    oldX=mouseX; oldY=mouseY;

    display();

}


int main(int argc, char** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("week05");

    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);

    glutMouseFunc(mouse);

    glutMotionFunc(motion);

    glutMainLoop();

}


縮放

#include <GL/glut.h>

#include<stdio.h>

float x=150, y=150, z=0, scale=1.0;

int oldX=0, oldY=0;

void display()

{

    glClearColor(0.5,0.5,0.5,1);

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix();

        glTranslatef((x-150)/150.0, -(y-150)/150.0,z);

        glScalef(scale, scale, scale);

        glColor3f(1,1,0);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

void keyboard( unsigned char key,int x,int y)

{

}

void mouse(int button,int state,int mouseX,int mouseY)

{

    oldX=mouseX; oldY=mouseY;

}

void motion(int mouseX,int mouseY)

{


    if(mouseX-oldX>0) scale*=1.01;

    if(mouseY-oldY<0) scale*=0.99;

    oldX=mouseX; oldY=mouseY;

    display();

}


int main(int argc, char** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("week05");

    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);

    glutMouseFunc(mouse);

    glutMotionFunc(motion);

    glutMainLoop();

}




2022年3月15日 星期二

啵咕咕的圖學筆記week04

week04

跟上周一樣,這次調rotate






旋轉程式

#include<GL/glut.h>


void display()


{

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glPushMatrix();

glRotatef(90, 0,0,1);

glutSolidTeapot(0.3);

glPopMatrix();

glutSwapBuffers();

}

用滑鼠旋轉

#include<GL/glut.h>

float angle=0;

void display()

{


    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix();

        glRotatef(angle, 0,0,1);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

void motion(int x, int y)

{

    angle=x;

    display();

}

int main(int argc, char** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("week04_rotate");


    glutDisplayFunc(display);

    glutMotionFunc(motion);

    glutMainLoop();

}


修治精準度
#include<GL/glut.h>
float angle=0, oldX=0;
void display()
{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glPushMatrix();
        glRotatef(angle, 0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x, int y)
{
    angle += (x-oldX);
    oldX = x;
    display();
}
void mouse(int button, int state,int x,int y)
{
    oldX = x;///定錨
}
int main(int argc, char** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week04_rotate");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutMainLoop();
}




2022年3月8日 星期二

啵咕咕的圖學筆記 week03

 Week03 1-1進到https://jsyeh.org/3dcg10,下載data、win32       

再將windows.zip、data.zip解壓縮 1-2將data放到windows裡面,執行Transformation.exe,試試看換模型及調整下方



上週程式新增

void display()

{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


    glPushMatrix(); 備份矩陣 移動會累積,因為會修改矩陣

    glTranslated(0.5,0.5,0); 右上角

    glColor3f(1,1,0);

    glutSolidTeapot(0.3);

    glPopMatrix();還原矩陣(舊的位置)

    glutSwapBuffers();

}


進階:

#include <GL/glut.h>

void myteapot(float x, float y)

{

    glPushMatrix();

    glTranslatef(x, y,0);

    glColor3f(1,1,0);

    glutSolidTeapot(0.3);

    glPopMatrix();

}


void display()


{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    myteapot(0.5,0.5);

    myteapot(0.5,-0.5);

    myteapot(-0.5,0.5);

    myteapot(-0.5,-0.5);

    glutSwapBuffers();

}


int main(int argc, char** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("week03 移動");


    glutDisplayFunc(display);


    glutMainLoop() ;

    }



用滑鼠寫程式:

#include<GL/glut.h>

#include<stdio.h>

float mouseX=0, mouseY=0;

void myteapot(float x, float y)


{

    glPushMatrix();

    glTranslatef(x, y, 0);

    glColor3f(1,1,0);

    glutSolidTeapot(0.1);

    glPopMatrix();

}


void display()


{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    myteapot( (mouseX-150)/150.0,-(mouseY-150)/150.0); 座標換算

    glutSwapBuffers();

}

void mouse(int button, int state, int x, int y)

{

    printf("%d %d %d %d\n", button ,state,x,y);

    mouseX=x; mouseY=y;

}


int main(int argc, char** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("week03 ²¾°Ê");


    glutDisplayFunc(display);

    glutMouseFunc(mouse);

    glutMainLoop() ;

    }




2022年3月1日 星期二

啵咕咕的圖學筆記 week02

 1.   下載範例 https://jsyeh.org/3dcg10

        data.zip windows.zip glut32.dll

2.     data.zip=解壓=>下載\windows\data\模型

        windows.zip=解壓=>windows\Shapes.exe

        glut32.dll=複製=> 下載\windows\glut32.dll

3.     跑 Shape.exe 看範例試試看

左按右鍵選單:大頂點 多色

右按右鍵選單:point...polygon



1. 上週的安裝 Git for Windows
2. 上週的 Git Bash: cd desktop, git clone 你的網址
   cd 2022graphics1
3. 上週的安裝 freeglut, 記得改檔名 lib\libglut32.a
4. 在 CodeBlocks File-Open week01_GLUT專案,跑!


我們要寫出今天的 week02_color 新專案
1. File-New-Project,選GLUT專案
2. 設好freeglut後
3. 確定有上週的進度後, 大膽的把上週的程式刪掉
4. 寫下今天的10行程式碼,會秀出黃色的茶壼

///step02-1 10行最精簡的 GLUT程式
///先全刪, 目標: 5-10行,寫完
#include <GL/glut.h> ///使用GLUT外掛,簡化程式

void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///畫圖前, 先清畫面

    glColor3f(1,1,0); ///設定色彩
    glutSolidTeapot(0.3); ///實心的茶壼

    glutSwapBuffers();///畫好後,交換出來
}

int main(int argc, char** argv) ///main()主函式 進階版
{
    glutInit( &argc, argv); ///把參數,送給 glutInit 初始化
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH ); ///雙緩衡區 + 3D深度功能
    glutCreateWindow("第02週的程式"); ///開 GLUT 視窗

    glutDisplayFunc(display); ///用來顯示的函式

    glutMainLoop(); ///主要的程式迴圈
}

2022年2月22日 星期二

啵咕咕的圖學筆記 week01

第一個opengl程式
codeblocks 17.12 mingw 裝好
file-new-project-選opengl 專案
在點點點的目錄選桌面-projectsje nir 01_opengl













下一步×2,完成後,build&run
可以看到有色彩旋轉的三角型





















 登入 GITHUB.com 

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...