OpenGL programming book-6.9

Source: Internet
Author: User

Test test... to put it simply. I just wrote an ADS lighting model, that is, environment light, diffuse reflection, and mirror reflection, which jointly affect the illumination of vertices. the Vertex coloring tool is used.

Thanks to the previous study on the fixed assembly line, learning this is really simple, haha! You only need to write the processing for each vertex, including Coordinate System Transformation and illumination calculation, and then submit it to the Assembly Line for completion. my thoughts are much clearer. I believe it will be easy to continue with the next step. ke, indeed, this thing is not written by myself. It's just a look, and it's useless. I really feel that I didn't add anything after cropping to my CPU assembly line. If I want to do something, it will be nice if I want to study it ~

Today is Friday, the last two days have a cold, the last few days have a cold, cough hard, finally it is good ~ We are about to start a new job next week. Recently, we have studied the skeleton animation and textures ~ Very tired ~

It's hard to find a cheap bed to live in ~ I'm looking forward to a smooth job change. After all, I often stay here, and I'm not excited to answer anything. I'm fake, why, and emotional factors. Let's make your own decisions.

Call ~ This book looks very fast. Squeeze the oil!

... Forgot to post code...,... make up... 2 !!

#include "stdafx.h"#include <GLTools.h>// OpenGL toolkit#include <GLMatrixStack.h>#include <GLFrame.h>#include <GLFrustum.h>#include <GLGeometryTransform.h>#include <StopWatch.h>#include <math.h>#ifdef __APPLE__#include <glut/glut.h>#else#define FREEGLUT_STATIC#include <GL/glut.h>#endifGLFrame viewFrame;GLFrustum viewFrustum;GLTriangleBatch sphereBatch;GLMatrixStack modelViewMatrix;GLMatrixStack projectionMatrix;GLGeometryTransform transformPipeline;GLShaderManager shaderManager;GLuint ADSLightShader;GLintlocAmbient;GLint locDiffuse;GLint locSpecular;GLint locLight;GLintlocMVP;GLintlocMV;GLintlocNM;void SetupRC(void){glClearColor(0.0f, 0.0f, 0.0f, 1.0f );glEnable(GL_DEPTH_TEST);glEnable(GL_CULL_FACE);    shaderManager.InitializeStockShaders();    viewFrame.MoveForward(4.0f);    gltMakeSphere(sphereBatch, 1.0f, 26, 13);ADSLightShader = shaderManager.LoadShaderPairWithAttributes("ADSGouraud.vp", "ADSGouraud.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex",GLT_ATTRIBUTE_NORMAL, "vNormal");locAmbient = glGetUniformLocation(ADSLightShader, "ambientColor");locDiffuse = glGetUniformLocation(ADSLightShader, "diffuseColor");locSpecular = glGetUniformLocation(ADSLightShader, "specularColor");locLight = glGetUniformLocation(ADSLightShader, "lightPosition");locMVP = glGetUniformLocation(ADSLightShader, "mvpMatrix");locMV  = glGetUniformLocation(ADSLightShader, "mvMatrix");locNM  = glGetUniformLocation(ADSLightShader, "normalMatrix");}void ShutdownRC(void){}void RenderScene(void){static CStopWatch rotTimer;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    modelViewMatrix.PushMatrix(viewFrame);modelViewMatrix.Rotate(rotTimer.GetElapsedSeconds() * 10.0f, 0.0f, 1.0f, 0.0f);GLfloat vEyeLight[] = { -100.0f, 100.0f, 100.0f };GLfloat vAmbientColor[] = { 0.1f, 0.1f, 0.1f, 1.0f };GLfloat vDiffuseColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };GLfloat vSpecularColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };glUseProgram(ADSLightShader);glUniform4fv(locAmbient, 1, vAmbientColor);glUniform4fv(locDiffuse, 1, vDiffuseColor);glUniform4fv(locSpecular, 1, vSpecularColor);glUniform3fv(locLight, 1, vEyeLight);glUniformMatrix4fv(locMVP, 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix());glUniformMatrix4fv(locMV, 1, GL_FALSE, transformPipeline.GetModelViewMatrix());glUniformMatrix3fv(locNM, 1, GL_FALSE, transformPipeline.GetNormalMatrix());    sphereBatch.Draw();    modelViewMatrix.PopMatrix();    glutSwapBuffers();glutPostRedisplay();}void ChangeSize(int w, int h){if(h == 0)h = 1;    glViewport(0, 0, w, h);    viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 100.0f);        projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());    transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);}int main(int argc, char* argv[]){gltSetWorkingDirectory(argv[0]);glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);glutInitWindowSize(800, 600);glutCreateWindow("ADS Lighting, Gouraud Shading");    glutReshapeFunc(ChangeSize);    glutDisplayFunc(RenderScene);GLenum err = glewInit();if (GLEW_OK != err) {fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));return 1;    }SetupRC();    glutMainLoop();ShutdownRC();return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.