OpenGL ES for Android(简单光照)

这篇博客介绍了在Android中使用OpenGL ES学习光照知识,包括光源和物体的定义、颜色设置。通过设置观察点和光源位置,展示了立方体在光照下的效果,并探讨了与现实世界光照差异,为后续深入学习光照效果打下基础。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简介

从这篇开始学习光照相关的知识,可以先阅读文档https://learnopengl-cn.github.io/02%20Lighting/01%20Colors/,了解光照的相关概念。

案例分析

光照至少需要一个光源和一个物体才能显示出的效果,那么我们就需要定义光源和物体的顶点位置和颜色,参考我们实现立方体的文章添加立方体并设置颜色,设置光源的颜色是白色,设置物体本来的颜色是橘色,那么光源照射之后的颜色就是两种颜色的叠加,我们直接设置颜色,物体着色器的代码如下:

 vertexShaderCode =
              "uniform mat4 uMVPMatrix;" +
                      "attribute vec4 aPosition;" +
                      "varying vec3 lColor;" +
                      "varying vec3 oColor;" +
                      "void main() {" +
                      "  gl_Position = uMVPMatrix * aPosition;" +
                      "  lColor = vec3(1.0, 1.0, 1.0);" +
                      "  oColor = vec3(1.0, 0.5, 0.31);" +
                      "}";
      fragmentShaderCode =
              "precision mediump float;" +
                      "varying vec3 lColor;" +
              
In Pro OpenGL ES for Android, you'll find out how to harness the full power of OpenGL ES, and design your own 3D applications by building a fully-functional 3D solar system model using Open GL ES! OpenGL has set the standard for 3D computer graphics, and is an essential aspect of Android development. This book offers everything you need to know, from basic mathematical concepts to advanced coding techniques. You'll learn by building a fascinating 3D solar system simulator! After introducing Open GL ES, Pro OpenGL ES for Android explains the basics of 3D math and then orients you to the native Android 3D libraries you'll be using in your own 3D games and the solar system project you'll build using this book. Through the solar system example project, you'll learn how to incorporate a variety of graphic and animation techniques into your applications. You will also discover how the full spectrum of 3D development that awaits, with topics such as lighting, texture-mapping, modeling, shaders, blending modes, and several more advanced concepts. By the time you finish Pro OpenGL ES for Android, you'll have learned all the skills you'll need to build your own incredible 3D applications, based on one of the most powerful 3D libraries available. What you'll learn * The basics of 3D mathematics, and how they are applied in the OpenGL library * How to design and build your 3D worlds * To create 2D interfaces within the 3D world * To develop animation and 3D movement * How to implement 3D shading, coloring, and texturing * The differences between OpenGL and other 3D toolkits * To build a fully-functional 3D solar system simulator using OpenGL ES Who this book is for Experienced Android programmers who want to enter the 3D world of OpenGL ES programming. Table of Contents * Introduction to OpenGL ES and Our 3D Solar System Project * Generating a Basic OpenGL Program * Getting Past the 3D Math * Shading, Lighting and Colors * Materials and Textures * Animation * Creating a User Interface * Blending Modes, Buffer Objects, and Other Cool Stuff * Latest Features of OpenGL ES * Ray Tracing, Hidden Surfaces, and Other Advanced Topics Appendix A: APIs
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值