OpenGL SuperBible阅读笔记

来源:互联网 发布:税务师含金量知乎 编辑:程序博客网 时间:2024/05/17 04:13

第二章 第一个OpenGL程序



Preface

After reading this book, readers should be comfortable looking up finer details in the OpenGL specification, experimenting with OpenGL on their machines, and using extensions.

OpenGL的作用

OpenGL is an interface that your application can use to access and control the graphics subsystem of the device on which it runs.

Standardizing the interface to a subsystem increases probability and allows software developers to concentrate on creating quality applications, producing interesting content, and ensuring the overall performance of their applications, rather than worrying about the specifics of the platforms they want them to run on.

Scalability and Parallelism

Through a combination of pipelining and parallelism, incredible performance of modern graphics processors is realized.

OpenGL的目标

The goal of OpenGL is to provide an abstraction layer between your application and the underlaying graphics subsystem, which is often a hardware accelerator made up of one or more custom, high-performance processors with dedicated memory, display outputs, and so on.

sb7框架

sb7框架写的程序都继承于sb7::application类,这个框架使用glfw作为图形输出,用gl3w加载gl核心函数。

父类的virtual函数只能只要实现就可以调用。

变色的例子,利用的glfwCurrentTime获取当前的时间。

    virtual void render(double currentTime)    {        const GLfloat color[] = {           (float)sin(currentTime) * 0.5f + 0.5f, (float) cos(currentTime) * 0.5f + 0.5f, 0.0f, 1.0f        };        glClearBufferfv(GL_COLOR, 0, color);    }
The minimal useful pipeline configuration consists of only a vertex shader, but if you wish to see any pixels on the screen, you will also need a fragment shader.

All variables taht start with gl_ are part of OpenGL and connect shaders to each other or to the various parts of fixed functionality in OpenGL.

One final thing that we need to do before we can draw anything is to create a vertex array object(vAO), which is an object that represents the vertex fetch stage of the OpenGL pipeline and is used to supply input to the vertex shader.



第一章 介绍

Current GPUs consist of large numbers of small programmable processors called shader cores that run mini-programs called shaders.

图形流水线

The graphics system is broken into a number of stages, each represented either by a shader or by a fixed-function, possibly configurable processing block.

两种版本,核心版本和兼容版本

The first is the modern, core profile, which removes a number of legacy features, leaving only those that are truly accelerated by current graphics hardware.

The compatibility profile maintains backward compatibility with all revision of OpenGL back to version 1.0.

The fundamental unit of rendering in OpenGL is known as the primitive. OpenGL many types of primitives, but the three basic renderable primitive types are points, lines, and triangles.

显示原理

Applications will normally break complex surfaces into a very large number of triangles and send them to OpenGL, where they are rendered using a hardware accelerator called a rasterizer.


As polygons, triangles are always convex, so filling rules are easy to device and follow.

Concave polygons can always be broken down into two or more triangle,

The rasterizer is dedicated hardware that converts the three-dimensional representation of a triangle into a series of pixels that need to be drawn onto the screen.

顶点

A vertex is simply a point within a coordinate space.

流水线工作原理

The graphics pipeline is broken down into two major parts.

The first part, often known as the front end, processes vertices and primitives, eventually forming them into the points, lines, and triangles that will be handed off to the rasterizer. This is known as primitive assembly.

After going through the rasterizer, the geometry has been converted from what is essentially a vector representation into a large number of independent pixels. These are handed off to the back end, which includes depth and stencil testing, fragment shading, blending, and updating of the output image.




原创粉丝点击