//
#include "stdafx.h"
#include<glew.h>
#include <glut.h>
#pragma comment(lib, "glew32.lib")
#pragma comment( lib, "glut32.lib ")
#define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes))
#define VERTICES 0
#define INDICES 1
#define NUM_BUFFERS 2
GLuint buffers[NUM_BUFFERS];
#define FACE_CNT 2
GLuint ids[FACE_CNT] = { 0 };
GLuint framebuffer = 0;
GLuint renderbuffer =0;
int height = 512;
int width = 512;
void changeSize(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1, 30);
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//一定得加
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(30.0f, 1.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLES);
//第一個三角形
glColor3f(0.f, 0.0f, 1.0f); //blue
glVertex3f(1.0f, 0.5f, 0.50f);
glVertex3f(-0.5f, 1.0f, 0.50f);
glVertex3f(-1.0f, -1.0f, 0.50f);
//第二個三角形
glColor3f(1.0f, 0.0f, 0.0f); //red
glVertex3f(1.0f, 1.0f, -0.5f);
glVertex3f(-1.0f, 1.0f, -0.5f);
glVertex3f(-1.0f, -1.0f, -0.5f);
glEnd();
glutSwapBuffers();
}
void init(void)
{
glewInit();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
//glClearDepth(1.0f); // Set background depth to farthest
glEnable(GL_DEPTH_TEST); // Enable depth testing for z-culling
glDepthFunc(GL_LESS); // Set the type of depth-test
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("Buffer Demo");
glutReshapeFunc(changeSize);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}