// This function does any needed initialization on the rendering context. static void SetupRC(void) { // Background glClearColor(0.2f, 0.2f, 0.3f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .70f, 0.30f, 32, 16); cullingShader = gltLoadShaderTripletWithAttributes("../../Data/Shaders/Chapter11/GSCulling.vs", "../../Data/Shaders/Chapter11/GSCulling.gs", "../../Data/Shaders/Chapter11/GSCulling.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVP = glGetUniformLocation(cullingShader, "mvpMatrix"); locMV = glGetUniformLocation(cullingShader, "mvMatrix"); locNM = glGetUniformLocation(cullingShader, "normalMatrix"); locViewpoint = glGetUniformLocation(cullingShader, "viewpoint"); }
// This function does any needed initialization on the rendering context. void SetupRC(void) { // Background glClearColor(0.2f, 0.2f, 0.3f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .70f, 0.10f, 11, 7); explodeProgram = gltLoadShaderTripletWithAttributes("../../Data/Shaders/Chapter11/GSExplode.vs", "../../Data/Shaders/Chapter11/GSExplode.gs", "../../Data/Shaders/Chapter11/GSExplode.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVP = glGetUniformLocation(explodeProgram, "mvpMatrix"); locMV = glGetUniformLocation(explodeProgram, "mvMatrix"); locNM = glGetUniformLocation(explodeProgram, "normalMatrix"); locPushOut = glGetUniformLocation(explodeProgram, "push_out"); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.025f, 0.25f, 0.25f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .80f, 0.25f, 52, 26); toonShader = gltLoadShaderPairWithAttributes("ToonShader.vp", "ToonShader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locLight = glGetUniformLocation(toonShader, "vLightPosition"); locMVP = glGetUniformLocation(toonShader, "mvpMatrix"); locMV = glGetUniformLocation(toonShader, "mvMatrix"); locNM = glGetUniformLocation(toonShader, "normalMatrix"); locColorTable = glGetUniformLocation(toonShader, "colorTable"); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_1D, texture); GLubyte textureData[4][3] = { 32, 0, 0, 64, 0, 0, 128, 0, 0, 255, 0, 0}; glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); }
////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering // context. void SetupRC() { // Initialze Shader Manager shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // This makes a torus gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30); // This make a sphere gltMakeSphere(sphereBatch, 0.1f, 26, 13); floorBatch.Begin(GL_LINES, 324); for(GLfloat x = -20.0; x <= 20.0f; x+= 0.5) { floorBatch.Vertex3f(x, -0.55f, 20.0f); floorBatch.Vertex3f(x, -0.55f, -20.0f); floorBatch.Vertex3f(20.0f, -0.55f, x); floorBatch.Vertex3f(-20.0f, -0.55f, x); } floorBatch.End(); // Randomly place the spheres for(int i = 0; i < NUM_SPHERES; i++) { GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f); GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f); spheres[i].SetOrigin(x, 0.0f, z); } }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .80f, 0.25f, 52, 26); ADSDissloveShader = gltLoadShaderPairWithAttributes("Dissolve.vp", "Dissolve.fp", 3, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal", GLT_ATTRIBUTE_TEXTURE0, "vTexCoords0"); locAmbient = glGetUniformLocation(ADSDissloveShader, "ambientColor"); locDiffuse = glGetUniformLocation(ADSDissloveShader, "diffuseColor"); locSpecular = glGetUniformLocation(ADSDissloveShader, "specularColor"); locLight = glGetUniformLocation(ADSDissloveShader, "vLightPosition"); locMVP = glGetUniformLocation(ADSDissloveShader, "mvpMatrix"); locMV = glGetUniformLocation(ADSDissloveShader, "mvMatrix"); locNM = glGetUniformLocation(ADSDissloveShader, "normalMatrix"); locTexture = glGetUniformLocation(ADSDissloveShader, "cloudTexture"); locDissolveFactor = glGetUniformLocation(ADSDissloveShader, "dissolveFactor"); glGenTextures(1, &cloudTexture); glBindTexture(GL_TEXTURE_1D, cloudTexture); LoadTGATexture("Clouds.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); }
////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering // context. void SetupRC() { // Make sure OpenGL entry points are set glewInit(); // Initialze Shader Manager shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // This makes a torus gltMakeTorus(torusBatch, 0.4f, 0.15f, 40, 20); // This makes a sphere gltMakeSphere(sphereBatch, 0.1f, 26, 13); // Make the solid ground GLfloat texSize = 10.0f; floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1); floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f); floorBatch.MultiTexCoord2f(0, texSize, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, 20.0f); floorBatch.MultiTexCoord2f(0, texSize, texSize); floorBatch.Vertex3f(20.0f, -0.41f, -20.0f); floorBatch.MultiTexCoord2f(0, 0.0f, texSize); floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f); floorBatch.End(); // Make 3 texture objects glGenTextures(3, uiTextures); // Load the Marble glBindTexture(GL_TEXTURE_2D, uiTextures[0]); LoadTGATexture("marble.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); // Load Mars glBindTexture(GL_TEXTURE_2D, uiTextures[1]); LoadTGATexture("marslike.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); // Load Moon glBindTexture(GL_TEXTURE_2D, uiTextures[2]); LoadTGATexture("moonlike.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); // Randomly place the spheres for(int i = 0; i < NUM_SPHERES; i++) { GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f); GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f); spheres[i].SetOrigin(x, 0.0f, z); } }
////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering // context. void SetupRC() { // Initialze Shader Manager shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); #ifndef OPENGL_ES glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); #else torusBatch.SetPrimitiveType(GL_LINE_LOOP); #endif glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // This makes a torus gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30); floorBatch.Begin(GL_LINES, 324); for(GLfloat x = -20.0; x <= 20.0f; x+= 0.5) { floorBatch.Vertex3f(x, -0.55f, 20.0f); floorBatch.Vertex3f(x, -0.55f, -20.0f); floorBatch.Vertex3f(20.0f, -0.55f, x); floorBatch.Vertex3f(-20.0f, -0.55f, x); } floorBatch.End(); }
void SetupRC(void) { shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gltMakeSphere(sphereBatch, 0.2f, 26, 13); gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30); for (size_t i = 0; i < NUM_SPHERES; ++i) { float x = (GLfloat(rand() % 400) - 200.0f) * 0.1f; float z = (GLfloat(rand() % 400) - 200.0f) * 0.1f; sphereFrames[i].SetOrigin(x, 0.0f, z); } //Make the solid ground GLfloat texSize = 10.0f; floorBatch.Begin(GL_TRIANGLE_FAN, 4,1); { //没看懂纹理和顶点的映射关系 floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f); floorBatch.MultiTexCoord2f(0, texSize, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, 20.0f); floorBatch.MultiTexCoord2f(0, texSize, texSize); floorBatch.Vertex3f(20.0f, -0.41f, -20.0f); floorBatch.MultiTexCoord2f(0, 0.0f, texSize); floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f); } floorBatch.End(); // Make 3 texture objects glGenTextures(3, uiTextures); // Load the Marble glBindTexture(GL_TEXTURE_2D, uiTextures[0]); LoadTGATexture("marble.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); // Load Mars glBindTexture(GL_TEXTURE_2D, uiTextures[1]); LoadTGATexture("marslike.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); // Load Moon glBindTexture(GL_TEXTURE_2D, uiTextures[2]); LoadTGATexture("moonlike.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); }
// This function does any needed initialization on the rendering // context. void SetupRC() { // Black background glClearColor(0.3f, 0.3f, 0.3f, 1.0f ); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(7.0f); // Make the torus gltMakeTorus(torusBatch, 1.0f, 0.3f, 52, 26); glPointSize(4.0f); }
void SetupRC() { glClearColor(0.8f, 0.8f, 0.8f, 1.0f); glEnable(GL_DEPTH_TEST); shaderManger.InitializeStockShaders(); gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30); //线填充,绘制前后两面 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); }
void SetupRC(void) { // Make sure OpenGL entry points are set //glewInit(); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gltMakeTorus(torusBatch, 0.3f, 0.1f, 52, 26); gltMakeSphere(sphereBatch, 0.1f, 26, 13); //make the solid ground GLfloat texSize = 10.0f; floorBatch.Begin(GL_TRIANGLE_FAN,4,1); floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f); floorBatch.Vertex3f(-20.f, -0.41f, 20.f); floorBatch.MultiTexCoord2f(0, texSize, 0.0f); floorBatch.Vertex3f(20.f, -0.41f, 20.f); floorBatch.MultiTexCoord2f(0, texSize, texSize); floorBatch.Vertex3f(20.f, -0.41f, -20.f); floorBatch.MultiTexCoord2f(0, 0.0f, texSize); floorBatch.Vertex3f(-20.f, -0.41f, -20.f); floorBatch.End(); int x = 400; int y = 200; int width = 300; int height = 155; logoBatch.Begin(GL_TRIANGLE_FAN, 4, 1); //像素点的原点是左上角, 根据GL_TRIANGLE_FAN 做了调整 // Upper left hand corner logoBatch.MultiTexCoord2f(0, 0.0f, height); logoBatch.Vertex3f(x, y, 0.0f); logoBatch.MultiTexCoord2f(0, 0.0f, 0.0f); logoBatch.Vertex3f(x, y - height, 0.0f); // Lower right hand corner logoBatch.MultiTexCoord2f(0, width, 0.0f); logoBatch.Vertex3f(x + width, y - height, 0.0f); // Upper righ hand corner logoBatch.MultiTexCoord2f(0, width, height); logoBatch.Vertex3f(x + width, y, 0.0f); logoBatch.End(); glGenTextures(4, uiTextures); // Load the Marble glBindTexture(GL_TEXTURE_2D, uiTextures[0]); LoadTGATexture("marble.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); // Load Mars glBindTexture(GL_TEXTURE_2D, uiTextures[1]); LoadTGATexture("marslike.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); // Load Moon glBindTexture(GL_TEXTURE_2D, uiTextures[2]); LoadTGATexture("moonlike.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); // Load the Logo glBindTexture(GL_TEXTURE_RECTANGLE, uiTextures[3]); LoadTGATextureRect("OpenGL-Logo.tga", GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE); sphereWolrdShader = gltLoadShaderPairWithAttributes("RectReplace.vp", "RectReplace.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_TEXTURE0, "vTexCoord"); locMVP = glGetUniformLocation(sphereWolrdShader, "mvpMatrix"); locTexture = glGetUniformLocation(sphereWolrdShader, "rectangleImage"); // -200,200 // Randomly place the spheres for (int i = 0; i < NUM_SPHERES; i++) { GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f); GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f); spheres[i].SetOrigin(x, 0.0f, z); } }
/////////////////////////////////////////////////////////////////////////////// // OpenGL related startup code is safe to put here. Load textures, etc. void SetupRC(void) { #ifndef ANGLE GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } #endif // Initialze Shader Manager shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); // Black glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gltMakeTorus(torusBatch, 0.4f, 0.15f, 35, 35); GLfloat alpha = 0.25f; floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 10.0f, 0.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, 20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 10.0f, 10.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, -20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 0.0f, 10.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f); floorBatch.End(); glGenTextures(1, textures); glBindTexture(GL_TEXTURE_2D, textures[0]); LoadBMPTexture("marble.bmp", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); // Create blur program blurProg = gltLoadShaderPairWithAttributes("blur.vs", "blur.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_TEXTURE0, "texCoord0"); // Create blur textures glGenTextures(6, blurTextures); // XXX I don't think this is necessary. Should set texture data to NULL // Allocate a pixel buffer to initialize textures and PBOs pixelDataSize = screenWidth*screenHeight*3*sizeof(unsigned int); // XXX This should be unsigned byte void* data = (void*)malloc(pixelDataSize); memset(data, 0x00, pixelDataSize); // Setup 6 texture units for blur effect // Initialize texture data for (int i=0; i<6;i++) { glActiveTexture(GL_TEXTURE1+i); glBindTexture(GL_TEXTURE_2D, blurTextures[i]); #ifndef OPENGL_ES glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); #else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #endif glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, data); } // Alloc space for copying pixels so we dont call malloc on every draw #ifndef OPENGL_ES glGenBuffers(1, pixBuffObjs); glBindBuffer(GL_PIXEL_PACK_BUFFER, pixBuffObjs[0]); glBufferData(GL_PIXEL_PACK_BUFFER, pixelDataSize, pixelData, GL_DYNAMIC_COPY); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); #endif // Create geometry and a matrix for screen aligned drawing gltGenerateOrtho2DMat(screenWidth, screenHeight, orthoMatrix, screenQuad); // Make sure all went well gltCheckErrors(); }
/////////////////////////////////////////////////////////////////////////////// // OpenGL related startup code is safe to put here. Load textures, etc. void SetupRC() { #ifndef ANGLE GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } #endif // Initialze Shader Manager shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); // Black glClearColor(0.0f, 0.0f, 0.0f, 1.0f); #if defined __APPLE__ || defined ANGLE ninja.LoadFromSBM("ninja.sbm", GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_NORMAL, GLT_ATTRIBUTE_TEXTURE0); #else ninja.LoadFromSBM("../../../Src/Models/Ninja/ninja.sbm", GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_NORMAL, GLT_ATTRIBUTE_TEXTURE0); #endif gltMakeTorus(torusBatch, 0.4f, 0.15f, 35, 35); gltMakeSphere(sphereBatch, 0.1f, 26, 13); GLfloat alpha = 0.25f; floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 10.0f, 0.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, 20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 10.0f, 10.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, -20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 0.0f, 10.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f); floorBatch.End(); glGenTextures(1, textures); glBindTexture(GL_TEXTURE_2D, textures[0]); LoadBMPTexture("marble.bmp", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); glGenTextures(1, ninjaTex); glBindTexture(GL_TEXTURE_2D, ninjaTex[0]); #if defined __APPLE__ LoadBMPTexture("NinjaComp.bmp", GL_LINEAR, GL_LINEAR, GL_CLAMP); #elif defined ANGLE LoadBMPTexture("NinjaComp.bmp", GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); #else LoadBMPTexture("../../../Src/Models/Ninja/NinjaComp.bmp", GL_LINEAR, GL_LINEAR, GL_CLAMP); #endif glGenFramebuffers(1,&fboName); // Create depth renderbuffer glGenRenderbuffers(1, &depthBufferName); glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName); #ifndef ANGLE glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, screenWidth, screenHeight); #else glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screenWidth, screenHeight); #endif // Create 3 color renderbuffers glGenRenderbuffers(3, renderBufferNames); glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[0]); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight); glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[1]); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight); glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[2]); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight); // Attach all 4 renderbuffers to FBO glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBufferName); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBufferNames[0]); #ifndef OPENGL_ES glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderBufferNames[1]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, renderBufferNames[2]); #endif // See bind frag location in Chapter 9 processProg = gltLoadShaderPairWithAttributes("multibuffer.vs", "multibuffer_frag_location.fs", 3, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal", GLT_ATTRIBUTE_TEXTURE0, "texCoord0"); #ifndef OPENGL_ES glBindFragDataLocation(processProg, 0, "oStraightColor"); glBindFragDataLocation(processProg, 1, "oGreyscale"); glBindFragDataLocation(processProg, 2, "oLumAdjColor"); #endif glLinkProgram(processProg); #ifndef OPENGL_ES // Create 3 new buffer objects glGenBuffers(3,texBO); glGenTextures(1, &texBOTexture); int count = 0; float* fileData = 0; // Load first texBO with a tangent-like curve, 1024 values fileData = LoadFloatData("LumTan.data", &count); if (count > 0) { glBindBuffer(GL_TEXTURE_BUFFER_ARB, texBO[0]); glBufferData(GL_TEXTURE_BUFFER_ARB, sizeof(float)*count, fileData, GL_STATIC_DRAW); delete fileData; } // Load second texBO with a sine-like curve, 1024 values fileData = LoadFloatData("LumSin.data", &count); if (count > 0) { glBindBuffer(GL_TEXTURE_BUFFER_ARB, texBO[1]); glBufferData(GL_TEXTURE_BUFFER_ARB, sizeof(float)*count, fileData, GL_STATIC_DRAW); delete fileData; } // Load third texBO with a linear curve, 1024 values fileData = LoadFloatData("LumLinear.data", &count); if (count > 0) { glBindBuffer(GL_TEXTURE_BUFFER_ARB, texBO[2]); glBufferData(GL_TEXTURE_BUFFER_ARB, sizeof(float)*count, fileData, GL_STATIC_DRAW); delete fileData; } // Load the Tan ramp first glBindBuffer(GL_TEXTURE_BUFFER_ARB, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_BUFFER_ARB, texBOTexture); glTexBufferARB(GL_TEXTURE_BUFFER_ARB, GL_R32F, texBO[0]); #endif glActiveTexture(GL_TEXTURE0); // Reset framebuffer binding glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Make sure all went well gltCheckErrors(); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.2f, 0.2f, 0.3f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .70f, 0.10f, 11, 7); gltMakeCube(cubeBatch, 1.0f); toonShader = gltLoadShaderTripletWithAttributes("GSTessellate.vs", "GSTessellate.gs", "GSTessellate.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVP = glGetUniformLocation(toonShader, "mvpMatrix"); locMV = glGetUniformLocation(toonShader, "mvMatrix"); locNM = glGetUniformLocation(toonShader, "normalMatrix"); static const GLfloat vertices[] = { -1.0f, -1.0f, -1.0f, // A -1.0f, -1.0f, 1.0f, // B -1.0f, 1.0f, -1.0f, // C -1.0f, 1.0f, 1.0f, // D 1.0f, -1.0f, -1.0f, // E 1.0f, -1.0f, 1.0f, // F 1.0f, 1.0f, -1.0f, // G 1.0f, 1.0f, 1.0f // H }; static const GLshort indices[] = { 0, 1, 2, 3, 2, 1, 1, 5, 3, 7, 3, 5, 5, 4, 7, 6, 7, 4, 4, 0, 6, 2, 6, 0, 4, 5, 0, 1, 0, 5, 3, 7, 2, 6, 2, 7 }; glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(0); glGenBuffers(1, &element_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); GLenum e = glGetError(); }
/////////////////////////////////////////////////////////////////////////////// // OpenGL related startup code is safe to put here. Load textures, etc. void SetupRC() { GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } // Initialze Shader Manager shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); // Black glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gltMakeTorus(torusBatch, 0.4f, 0.15f, 35, 35); gltMakeSphere(sphereBatch, 0.1f, 26, 13); gltMakeCylinder(cylinderBatch,0.3f, 0.2f, 1.0, 10,10); GLfloat alpha = 0.25f; floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 10.0f, 0.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, 20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 10.0f, 10.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(20.0f, -0.41f, -20.0f); floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha); floorBatch.MultiTexCoord2f(0, 0.0f, 10.0f); floorBatch.Normal3f(0.0, 1.0f, 0.0f); floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f); floorBatch.End(); mirrorBatch.Begin(GL_TRIANGLE_FAN, 4, 1); mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f); mirrorBatch.MultiTexCoord2f(0, 0.0f, 0.0f); mirrorBatch.Normal3f( 0.0f, 1.0f, 0.0f); mirrorBatch.Vertex3f(-1.0f, 0.0f, 0.0f); mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f); mirrorBatch.MultiTexCoord2f(0, 1.0f, 0.0f); mirrorBatch.Normal3f(0.0f, 1.0f, 0.0f); mirrorBatch.Vertex3f(1.0f, 0.0f, 0.0f); mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f); mirrorBatch.MultiTexCoord2f(0, 1.0f, 1.0f); mirrorBatch.Normal3f(0.0f, 1.0f, 0.0f); mirrorBatch.Vertex3f(1.0f, 2.0f, 0.0f); mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f); mirrorBatch.MultiTexCoord2f(0, 0.0f, 1.0f); mirrorBatch.Normal3f( 0.0f, 1.0f, 0.0f); mirrorBatch.Vertex3f(-1.0f, 2.0f, 0.0f); mirrorBatch.End(); mirrorBorderBatch.Begin(GL_TRIANGLE_STRIP, 13); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(-1.0f, 0.1f, 0.01f); mirrorBorderBatch.Normal3f(0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(-1.0f, 0.0f, 0.01f); mirrorBorderBatch.Normal3f(0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(1.0f, 0.1f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(1.0f, 0.0f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(0.9f, 0.0f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(1.0f, 2.0f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(0.9f, 2.0f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(1.0f, 1.9f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(-1.0f, 2.f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(-1.0f, 1.9f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(-0.9f, 2.f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(-1.0f, 0.0f, 0.01f); mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f); mirrorBorderBatch.Vertex3f(-0.9f, 0.0f, 0.01f); mirrorBorderBatch.End(); glGenTextures(1, textures); glBindTexture(GL_TEXTURE_2D, textures[0]); LoadBMPTexture("marble.bmp", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); // Create and bind an FBO glGenFramebuffers(1,&fboName); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); // Create depth renderbuffer glGenRenderbuffers(1, &depthBufferName); glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, mirrorTexWidth, mirrorTexHeight); // Create the reflection texture glGenTextures(1, &mirrorTexture); glBindTexture(GL_TEXTURE_2D, mirrorTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mirrorTexWidth, mirrorTexHeight, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Attach texture to first color attachment and the depth RBO glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mirrorTexture, 0); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBufferName); // Make sure all went well gltCheckErrors(); // Reset framebuffer binding glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); }
void initTriangleBatch() { gltMakeTorus(torusBatch,1.0f,0.5f,50,25); gltMakeSphere(sphereBatch,0.3,32,32); gltMakeCylinder(cylinderBatch,1.0,0.5,1.0,16,32); }