OpenGL学习三:绘制矢量图形模型

glBegin(GL_TRIANGLES);
  glVertex3f( 0.0f, 1.0f, 0.0f);
  glVertex3f(-1.0f,-1.0f, 0.0f);
  glVertex3f( 1.0f,-1.0f, 0.0f);
 glEnd();

 

begin end 中间是构成矢量图形的点

 

#define GL_POINTS                         0x0000
#define GL_LINES                          0x0001
#define GL_LINE_LOOP                      0x0002
#define GL_LINE_STRIP                     0x0003
#define GL_TRIANGLES                      0x0004
#define GL_TRIANGLE_STRIP                 0x0005
#define GL_TRIANGLE_FAN                   0x0006
#define GL_QUADS                          0x0007
#define GL_QUAD_STRIP                     0x0008
#define GL_POLYGON                        0x0009

#include "header.h"

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)	
{
	if (height==0)									
	{
		height=1;									
	}

	glViewport(0,0,width,height);					

	glMatrixMode(GL_PROJECTION);					
	glLoadIdentity();							

	
	gluPerspective(25.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

	glMatrixMode(GL_MODELVIEW);							
	glLoadIdentity();							
}

int InitGL(void)										
{
	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);	
	return TRUE;										
}

void DrawGLScene(void)									
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity();									
	glTranslatef(-1.5f,0.0f,-6.0f);					
	glBegin(GL_TRIANGLES);								
		glVertex3f( 0.0f, 1.0f, 0.0f);				
		glVertex3f(-1.0f,-1.0f, 0.0f);					
		glVertex3f( 1.0f,-1.0f, 0.0f);				
	glEnd();										
	glTranslatef(3.0f,0.0f,0.0f);						
	glBegin(GL_QUADS);								
		glVertex3f(-1.0f, 1.0f, 0.0f);					
		glVertex3f( 1.0f, 1.0f, 0.0f);		
		glVertex3f( 1.0f,-1.0f, 0.0f);				
		glVertex3f(-1.0f,-1.0f, 0.0f);				
	glEnd();										
	glFlush();								
}


int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(640,480);
	glutCreateWindow("2D图形");
	glutReshapeFunc(ReSizeGLScene);
	glutDisplayFunc(DrawGLScene);

	InitGL();
	glutMainLoop();
	return 0;
}

 

你可能感兴趣的:(OpenGL)