
將windows解壓縮

把data資料夾、glut32.dll移至windows資料夾內

打開shape

2.
打開codeblocls開GLUT project選freeglut
打出程式再按build and run
#include <GL/glut.h>
void display()
{
glBegin(GL_POLYGON); //切換頂點跟色彩
glColor3f(1,1,0) ;//色彩
glVertex3f(0.5,0.5,0.5); //頂點
glVertex3f(0.5,-0.5,0.5) ;//頂點
glVertex3f(0,0,0) ;//頂點
glEnd(); //切換頂點跟色彩
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMainLoop();
}

改背景色

除255.0


或使用 glColor3ub(r, g, b);


點一下滑鼠及可找出座標

#include <GL/glut.h>
#include <stdio.h>
void mouse (int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
printf(" glVertex3f((%d-150)/150.0, -(%d-150)/150.0, 0.0);\n", x, y);
}
void display()
{
glClearColor(144/255.0, 168/255.0, 56/255.0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(192/255.0, 215/255.0, 107/255.0);
glVertex3f((95-100)/100.0, (49-100)/100.0, 0.0);
glVertex3f((17-100)/100.0, (106-100)/100.0, 0.0);
glVertex3f((93-100)/100.0, (165-100)/100.0, 0.0);
glVertex3f((174-100)/100.0, (103-100)/100.0, 0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}

#include <Gl/glut.h>
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
printf("glVertex3f((%d-150)/150.0, -(%d-150)/150.0, 0.0);\n", x, y);
}
void display()
{
glClearColor(144/255.0, 168/255.0, 56/255.0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3ub(192, 215, 107);
glVertex3f((95-100)/100.0,-(49-100)/100.0, 0.0);
glVertex3f((17-100)/100.0,-(106-100)/100.0, 0.0);
glVertex3f((93-100)/100.0,-(165-100)/100.0, 0.0);
glVertex3f((174-100)/100.0,-(103-100)/100.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f((27-150)/150.0, -(234-150)/150.0, 0.0);
glVertex3f((28-150)/150.0, -(270-150)/150.0, 0.0);
glVertex3f((92-150)/150.0, -(272-150)/150.0, 0.0);
glVertex3f((82-150)/150.0, -(241-150)/150.0, 0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言