1.
TRAIN_FAN
GL_LINE
GL_LINE_LOOP
POINTS
GL_POLYGON
GL_QUADS
GL_QUAD_STRIP
LINE_STRIP
GL_TRIANGLE_STRIP
GL_TRIANGLES
2.
Codeblock用程式畫三角形
程式碼:
1. 自己做一個三角形(同一個顏色)。
#include <GL/glut.h>
void display()
{
glBegin(GL_POLYGON);
glColor3f(0.5, 0.0, 0.3);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 1.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMainLoop();
}
void display()
{
glBegin(GL_POLYGON);
glColor3f(0.5, 0.0, 0.3);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 1.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMainLoop();
}
2. 三個點不同顏色
程式碼:
#include <GL/glut.h>
void display()
{
glBegin(GL_POLYGON);
glColor3f(0.5, 0.0, 0.3);
glColor3f(0.5, 0.0, 0.5); glVertex3f(0.0, 0.0, 0.0);
glColor3f(1.0, 0.0, 0.3); glVertex3f(1.0, 0.0, 0.0);
glColor3f(0.0, 0.5, 0.3); glVertex3f(1.0, 1.0, 1.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>
void display()
{
glBegin(GL_POLYGON);
glColor3f(0.5, 0.0, 0.3);
glColor3f(0.5, 0.0, 0.5); glVertex3f(0.0, 0.0, 0.0);
glColor3f(1.0, 0.0, 0.3); glVertex3f(1.0, 0.0, 0.0);
glColor3f(0.0, 0.5, 0.3); glVertex3f(1.0, 1.0, 1.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMainLoop();
}
3. 更改背景顏色,glClearColor(0.0, 0.8, 0.5, 1),
最後要加一個 1 。
程式碼:
#include <Gl/glut.h>
void display()
{
glClearColor(0.0, 0.8, 0.5, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(0.5, 0.0, 0.3);
glColor3f(0.5, 0.0, 0.5); glVertex3f(0.0, 0.0, 0.0);
glColor3f(1.0, 0.0, 0.3); glVertex3f(1.0, 0.0, 0.0);
glColor3f(0.0, 0.5, 0.3); glVertex3f(1.0, 1.0, 1.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMainLoop();
}
最後要加一個 1 。
程式碼:
#include <Gl/glut.h>
void display()
{
glClearColor(0.0, 0.8, 0.5, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(0.5, 0.0, 0.3);
glColor3f(0.5, 0.0, 0.5); glVertex3f(0.0, 0.0, 0.0);
glColor3f(1.0, 0.0, 0.3); glVertex3f(1.0, 0.0, 0.0);
glColor3f(0.0, 0.5, 0.3); glVertex3f(1.0, 1.0, 1.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMainLoop();
}
小畫家輔助
void display()
{
glBegin(GL_POLYGON);
glColor3f(1,1,0);
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glVertex3f(1,1,0);
glEnd();
glSwapBuffers();
}
沒有留言:
張貼留言