openGL着色器学习(一)
来源:互联网 发布:淘宝超市网址 编辑:程序博客网 时间:2024/05/17 00:00
顶点着色器
Identity.vp
// The Identity Shader// Vertex Shader// Richard S. Wright Jr.// OpenGL SuperBible#version 130in vec4 vVertex;void main(void) { gl_Position = vVertex; }
Identity.fp
// The Identity Shader// Fragment Shader// Richard S. Wright Jr.// OpenGL SuperBible#version 130out vec4 vFragColor;uniform vec4 vColor;void main(void) { vFragColor = vColor; }
主程序:
// Triangle.cpp// Our first OpenGL program that will just draw a triangle on the screen.#include <GLTools.h> // OpenGL toolkit#include <GLShaderManager.h> // Shader Manager Class#ifdef __APPLE__#include <glut/glut.h> // OS X version of GLUT#else#define FREEGLUT_STATIC#include <GL/glut.h> // Windows FreeGlut equivalent#endifGLBatchtriangleBatch;GLShaderManagershaderManager;GLintmyIdentityShader;///////////////////////////////////////////////////////////////////////////////// Window has changed size, or has just been created. In either case, we need// to use the window dimensions to set the viewport and the projection matrix.void ChangeSize(int w, int h) {glViewport(0, 0, w, h); }///////////////////////////////////////////////////////////////////////////////// This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks.void SetupRC(){// Blue backgroundglClearColor(0.0f, 0.0f, 1.0f, 1.0f ); shaderManager.InitializeStockShaders();// Load up a triangleGLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f };triangleBatch.Begin(GL_TRIANGLES, 3);triangleBatch.CopyVertexData3f(vVerts);triangleBatch.End();myIdentityShader = shaderManager.LoadShaderPairWithAttributes("Identity.vp", "Identity.fp", 1, GLT_ATTRIBUTE_VERTEX, "vVertex");}///////////////////////////////////////////////////////////////////////////////// Cleanupvoid ShutdownRC() { glDeleteProgram(myIdentityShader); }///////////////////////////////////////////////////////////////////////////////// Called to draw scenevoid RenderScene(void){// Clear the window with current clearing colorglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };glUseProgram(myIdentityShader);GLint iColorLocation = glGetUniformLocation(myIdentityShader, "vColor");GLfloat vColor[4] = { 1.0f, 0.0f, 0.0f, 1.0f };glUniform4fv(iColorLocation, 1, vColor);triangleBatch.Draw();// Perform the buffer swap to display back bufferglutSwapBuffers();}///////////////////////////////////////////////////////////////////////////////// Main entry point for GLUT based programsint main(int argc, char* argv[]){gltSetWorkingDirectory(argv[0]);glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);glutInitWindowSize(800, 600);glutCreateWindow("Triangle"); 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;}
0 0
- openGL着色器学习(一)
- OpenGL ES学习笔记(一)——基本用法、绘制流程与着色器编译
- opengl编程一(使用着色器)
- OpenGL着色器(二)
- opengl es学习笔记2(着色器补充,示例)
- OpenGL学习笔记5:着色器
- opengl 学习资料,详细介绍着色器
- OpenGL学习笔记5:着色器2
- OpenGL学习:几何着色器(geometry shader)
- OpenGL蓝宝书源码学习(十三)第六章——OpenGL着色器和着色语言
- OpenGL 动态波纹效果(着色器)
- Opengl(四)——着色器
- OpenGL基础教程(2):着色器
- OpenGL 着色器语言
- OpenGL着色器语言
- opengl顶点着色器
- OpenGL ES 着色器
- OpenGL着色器介绍
- F2812程序从Flash搬到RAM中运行(调试过程)
- javascript的那些事儿你都懂了吗
- linux 系统时间设置
- uml关系
- java socket (-) 简单socket
- openGL着色器学习(一)
- Understanding SVM
- 浅谈Django中的RequestContext和Context
- 笔记——C++ primer第二章 变量
- 理想化的Redis 集群
- 就算是生了病
- 恩,有了一点点做调研的感觉罗
- OCR of Hand-written Data using SVM
- jquery中的模糊匹配