- 浏览: 465230 次
- 性别:
- 来自: 西安
文章分类
最新评论
-
baiyingtao:
这些信息不太够,我们希望得到相关Keyword的段落,页码,区 ...
Lucene学习之使用Apache Tika进行文档内容抽取 -
王爱学志:
boolean isExist=false; 可以不用直接用 ...
去掉数组中重复元素的最高效算法 -
gavinj:
这些版本都太老了,这里贴出了xcode6系列下载地址,需要的朋 ...
xcode的各个版本的下载地址 -
最美的风景:
帮我大忙了
Android获得Location信息的方法 -
harvin:
yangwei0915 写道可以转载!谢谢。
android 中判断WiFi是否可用的可靠方法
What is this: This tutorial shows how to create colored 3D Objects using the OpenGL® ES cross-platform API.
What you learn: You will learn how easy it is, to create a Colored 3D Cube, using OpenGL® ES.
Problems/Questions: post here
Difficulty: 1.5 of 5
What it will look like:
Introduction:
Lets quote wikipedia first:
-
1. Setup the view and create a cube
(1.1. Start/Stop the animation if we are (not) viewing it)
2. Do some trigonometry (rotation)
3. Make the Cube paint itself
Most interesting:
What the heck do those values in the Cube-Constructor mean...
I hope you succeeded and understood this tutorial.
Please vote and/or leave a comment .
原文地址 http://www.anddev.org/colored_3d_cube-t4.html
Quote: |
OpenGL ES (OpenGL for Embedded Systems) is a subset of the OpenGL 3D graphics API designed for embedded devices such as mobile phones, PDAs, and video game consoles. It is defined and promoted by the Khronos Group, a graphics hardware and software industry consortium interested in open APIs for graphics and multimedia. |
Java: |
int one = 0x10000;
/* Every vertex got 3 values, for * x / y / z position in the kartesian space. */ int vertices[] = { -one, -one, -one, // Vertex Zero one, -one, -one, // Vertex Two one, one, -one, // Vertex ... -one, one, -one, -one, -one, one, one, -one, one, one, one, one, -one, one, one, // Vertex Seven }; |
Java: |
/* Every vertex has got its own color, described by 4 values
* R(ed) * G(green) * B(blue) * A(lpha) <-- Opticacy */ int colors[] = { 0, 0, 0, one, one, 0, 0, one, one, one, 0, one, 0, one, 0, one, 0, 0, one, one, one, 0, one, one, one, one, one, one, 0, one, one, one, }; |
Java: |
/* The last thing is that we need to describe some Triangles(三角形).
* A triangle got 3 vertices. * The confusing thing is, that it is important in which order * the vertices of each triangle are described. * So describing a triangle through the vertices: "0, 4, 5" * will not result in the same triangle as: "0, 5, 4" * You probably ask: Why the hell isn't that the same ??? * The reason for that is the call of: "gl.glFrontFace(gl.GL_CW);" * which means, that we have to describe the "visible" side of the * triangles by naming its vertices in a ClockWise order! * From the other side, the triangle will be 100% lookthru! * You can create a kind of magic mirror with that . */ byte indices[] = { 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 }; |
Java: |
/*
* Copyright (C) 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.samples.graphics; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.OpenGLContext; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.SystemClock; import android.view.View; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; import javax.microedition.khronos.opengles.GL10; /** * Example of how to use OpenGL|ES in a custom view * */ public class GLView1 extends Activity { @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(new GLView( getApplication() )); } @Override protected void onResume() { super.onResume(); //android.os.Debug.startMethodTracing("/tmp/trace/GLView1.dmtrace", // 8 * 1024 * 1024); } @Override protected void onStop() { super.onStop(); //android.os.Debug.stopMethodTracing(); } } class GLView extends View { /** * The View constructor is a good place to allocate our OpenGL context */ public GLView(Context context) { super(context); /* * Create an OpenGL|ES context. This must be done only once, an * OpenGL contex is a somewhat heavy object. */ mGLContext = new OpenGLContext(0); mCube = new Cube(); mAnimate = false; } /* * Start the animation only once we're attached to a window * @see android.view.View#onAttachedToWindow() */ @Override protected void onAttachedToWindow() { mAnimate = true; Message msg = mHandler.obtainMessage(INVALIDATE); mNextTime = SystemClock.uptimeMillis(); mHandler.sendMessageAtTime(msg, mNextTime); super.onAttachedToWindow(); } /* * Make sure to stop the animation when we're no longer on screen, * failing to do so will cause most of the view hierarchy to be * leaked until the current process dies. * @see android.view.View#onDetachedFromWindow() */ @Override protected void onDetachedFromWindow() { mAnimate = false; super.onDetachedFromWindow(); } /** * Draw the view content * * @see android.view.View#onDraw(android.graphics.Canvas) */ @Override protected void onDraw(Canvas canvas) { if (true) { /* * First, we need to get to the appropriate GL interface. * This is simply done by casting the GL context to either * GL10 or GL11. */ GL10 gl = (GL10)(mGLContext.getGL()); /* * Before we can issue GL commands, we need to make sure all * native drawing commands are completed. Simply call * waitNative() to accomplish this. Once this is done, no native * calls should be issued. */ mGLContext.waitNative(canvas, this); int w = getWidth(); int h = getHeight(); /* * Set the viewport. This doesn't have to be done each time * draw() is called. Typically this is called when the view * is resized. */ gl.glViewport(0, 0, w, h); /* * Set our projection matrix. This doesn't have to be done * each time we draw, but usualy a new projection needs to be set * when the viewport is resized. */ float ratio = (float)w / h; gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 2, 12); /* * dithering is enabled by default in OpenGL, unfortunattely * it has a significant impact on performace in software * implementation. Often, it's better to just turn it off. */ gl.glDisable(gl.GL_DITHER); /* * Usually, the first thing one might want to do is to clear * the screen. The most efficient way of doing this is to use * glClear(). However we must make sure to set the scissor * correctly first. The scissor is always specified in window * coordinates: */ gl.glClearColor(1,1,1,1); gl.glEnable(gl.GL_SCISSOR_TEST); gl.glScissor(0, 0, w, h); gl.glClear(gl.GL_COLOR_BUFFER_BIT); /* * Now we're ready to draw some 3D object */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -3.0f); gl.glScalef(0.5f, 0.5f, 0.5f); gl.glRotatef(mAngle, 0, 1, 0); gl.glRotatef(mAngle*0.25f, 1, 0, 0); gl.glColor4f(0.7f, 0.7f, 0.7f, 1.0f); gl.glEnableClientState(gl.GL_VERTEX_ARRAY); gl.glEnableClientState(gl.GL_COLOR_ARRAY); gl.glEnable(gl.GL_CULL_FACE); mCube.draw(gl); mAngle += 1.2f; /* * Once we're done with GL, we need to flush all GL commands and * make sure they complete before we can issue more native * drawing commands. This is done by calling waitGL(). */ mGLContext.waitGL(); } } // ------------------------------------------------------------------------ private static final int INVALIDATE = 1; private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { if (mAnimate && msg.what == INVALIDATE) { invalidate(); msg = obtainMessage(INVALIDATE); long current = SystemClock.uptimeMillis(); if (mNextTime < current) { mNextTime = current + 20; } sendMessageAtTime(msg, mNextTime); mNextTime += 20; } } }; private OpenGLContext mGLContext; private Cube mCube; private float mAngle; private long mNextTime; private boolean mAnimate; } class Cube { public Cube() { int one = 0x10000; /* Every vertex got 3 values, for * x / y / z position in the kartesian space. */ int vertices[] = { -one, -one, -one, one, -one, -one, one, one, -one, -one, one, -one, -one, -one, one, one, -one, one, one, one, one, -one, one, one, }; /* Every vertex has got its own color, described by 4 values * R(ed) * G(green) * B(blue) * A(lpha) <-- Opticacy */ int colors[] = { 0, 0, 0, one, one, 0, 0, one, one, one, 0, one, 0, one, 0, one, 0, 0, one, one, one, 0, one, one, one, one, one, one, 0, one, one, one, }; /* The last thing is that we need to describe some Triangles. * A triangle got 3 vertices. * The confusing thing is, that it is important in which order * the vertices of each triangle are described. * So describing a triangle through the vertices: "0, 4, 5" * will not result in the same triangle as: "0, 5, 4" * You probably ask: Why the hell isn't that the same ??? * The reason for that is the call of: "gl.glFrontFace(gl.GL_CW);" * which means, that we have to describe the "visible" side of the * triangles by naming its vertices in a ClockWise order! * From the other side, the triangle will be 100% lookthru! * You can create a kind of magic mirror with that . */ byte indices[] = { 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 }; // Buffers to be passed to gl*Pointer() functions // must be direct, i.e., they must be placed on the // native heap where the garbage collector cannot // move them. // // Buffers with multi-byte datatypes (e.g., short, int, float) // must have their byte order set to native order ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); vbb.order(ByteOrder.nativeOrder()); mVertexBuffer = vbb.asIntBuffer(); mVertexBuffer.put(vertices); mVertexBuffer.position(0); ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4); cbb.order(ByteOrder.nativeOrder()); mColorBuffer = cbb.asIntBuffer(); mColorBuffer.put(colors); mColorBuffer.position(0); mIndexBuffer = ByteBuffer.allocateDirect(indices.length); mIndexBuffer.put(indices); mIndexBuffer.position(0); } public void draw(GL10 gl) { gl.glFrontFace(gl.GL_CW); gl.glVertexPointer(3, gl.GL_FIXED, 0, mVertexBuffer); gl.glColorPointer(4, gl.GL_FIXED, 0, mColorBuffer); gl.glDrawElements(gl.GL_TRIANGLES, 36, gl.GL_UNSIGNED_BYTE, mIndexBuffer); } private IntBuffer mVertexBuffer; private IntBuffer mColorBuffer; private ByteBuffer mIndexBuffer; } |
This is the tricky part. I think that I described it good enough in them comment.
Lets take a look at two example triangles:
The Code
Original Source:
code.google.com
Modified by: Nicolas 'plusminus' Gramlich
In this code-block the color of all the 8 vertices are described, as '4' each: R(ed) G(reen) B(lue) A(lpha). (Alpha means Opticacy(透明度))
OpenGL SE will create the color-flows automatically!
That is pretty easy, each row stands for a single vertex, consisting of three values (x,y,z) which simply result in a point in the cartesian space.
So if you think of each codeline as one vertex you get something like this:
(Note: We only created the vertices, not the edges. I just added them, that the cube-structure becomes better visible.)
(Note2: You will see that the blue coordinate-system(坐标系) is located right in the middle of the cube)
Description:
What we will do is, create a custom view and using OpenGL ES in it to draw a colored cube.
The Main steps are(根据要绘制的图形设置图形的定点,如果是屏幕的正方形,需要设置4个顶点(x、y、
z的坐标)如果是立方体,则要设置8个顶点):
发表评论
-
Android的开发规范整理之界面刷新
2018-05-17 11:04 5641.后一个界面(Activity)的操作导致前一个界面(A ... -
Android的开发规范整理之Handler的使用
2018-05-17 10:53 7151.关于Handler的使用,在Activity或者Ser ... -
Android TV开发之模拟器的设置
2017-12-10 13:36 2073在进行Android TV开发时,会碰见模拟器显示的效果跟 ... -
activity 启动service的三种方式区别
2017-06-10 11:01 577在Activity中启动Service有三种情况,具体的启 ... -
android 获取sd卡路径的两种方法
2018-05-17 11:20 1292/** * 方法一 * @return ... -
android NDK 开发环境搭建
2016-08-20 21:46 6351.下载android ndk 推荐版本为:android ... -
android进阶-----解决scrollview嵌套listview的问题
2016-08-15 16:40 342在android开发中,经常会碰到在ScrollView中 ... -
部分android手机不支持USB Host功能
2015-11-02 16:07 1425在android开发USB功能时,少部分android的手 ... -
PhoneGap 安装配置时遇到的问题及解决办法
2015-09-23 14:36 993PhoneGap在3.0之后就不能 ... -
解决 “android New package not yet registered with the system.”问题
2015-05-03 12:21 1565在android开发中因为更换包名或者为activity设置 ... -
Xcode真机调试 could not lunch failed to get reply to handshake packet
2015-01-31 23:25 4079解决的办法是 通用--->还原--->还原所有设置 ... -
android使用.9,png图片作为背景的问题
2014-10-30 10:11 3392在android的开发中,很多的时候需要使用.9.png来做为 ... -
android的小问题:You need to use a Theme.AppCompat theme
2014-07-30 16:43 7256android的一个小问题: Caused by: ... -
ViewPager中添加百度地图MapView,Page切换时地图显示黑屏问题
2014-05-14 11:47 7258在ViewPager的选项卡中增加的Page多余3个,如果 ... -
百度地图与高德地图坐标转换
2014-05-13 10:42 2609android项目使用了百度地图的定位SDK,web端使用的 ... -
拟物化化设计和扁平化设计
2014-03-20 17:32 11221. 拟物化设计 skeuomorphism 代表作 ... -
html5在移动开发中优势和劣势
2014-03-06 10:46 3320现在html5的应用已经非常广泛了,尤其是在移动端得到了较 ... -
android Button selector不起作用
2013-11-24 20:43 2272我们在Android开发中,经常需要设置Button在不同 ... -
Android Button快速滑过,ACTION_UP事件不触发的问题的解决
2013-10-16 15:56 6362在android界面编程时,经常要实现当Button一直 ... -
Android调用系统短信功能发送短信
2013-04-17 15:28 1226android调用系统短信功能发送短信有两种方法, 第一 ...
相关推荐
各种unity shader教程需要的脚本资源。使用时在本地Asset目录下建立一个Hidden目录,然后把shader脚本放进去就可以了
Colored Time Range Selector A smart colored time range selector. Users can select just free time with a handy colorful range selector. Screen Shots Features Select a time range between 2 hours ...
标题中的"simulate_dual-colored_ball"指的是一个用于模拟双色球的程序,这通常是指彩票类游戏,其中包含两个不同颜色的球。这个程序可能包含了生成随机数、匹配中奖号码等功能,是通过编程语言实现的。从描述来看,...
【标题】"POJ2513-Colored Sticks【TrieTree+MergeSet+EulerPath】"涉及的是一道编程竞赛题目,主要考察参赛者的数据结构与算法应用能力,特别是Trie树(字典树)、并查集(MergeSet)以及欧拉路径(Euler Path)这...
本教程将围绕“(0129)-iOS/iPhone/iPAD/iPod源代码-进度条(Progress)-Colored ProgressView”这一主题,详细讲解如何自定义UIProgressView的颜色,以便让进度条更加符合你的应用设计。 首先,我们需要了解...
ln -s ../../irssi-colored-nicks/colored_nicks.pl 要自动启用脚本,请将其添加到~/.irssi/scripts/autorun/ : cd ~/.irssi/scripts/autorun ln -s ../colored_nicks.pl 转到.irssi并链接关联的主题,以便可以在...
fisher add decors/fish-colored- man omf install https://github.com/decors/fish-colored- man 颜色选择 如果要更改颜色,请在config.fish添加以下选项。 # Solarized Dark & Green highlight set -g man_blink ...
在这个“responsive-website-colored-columns”练习中,我们将聚焦于如何使用CSS来创建一个色彩鲜明且具有响应性的列布局。 首先,我们需要理解CSS的基础。CSS(Cascading Style Sheets)是用于描述HTML或XML(包括...
gem 'activerecord-colored_log_subscriber' 然后执行: $ bundle 或将其自己安装为: $ gem install activerecord-colored_log_subscriber 发展 签出仓库后,运行bin/setup来安装依赖项。 然后,运行bundle ...
Android Colored Vector Drawable Use this library to change colors of your vector drawables easily from your code. If you want to set a colored vector in Imageview: DrawableHelper .withContext(this...
bind) colored dyes on fabrics 1 Mordant has: An easy, configuration-free, API Support for nesting styles and colors Automatic detection of terminal color support Support for 256 and 24-bit colors, ...
A flood fill game for Android by GunshipPenguin (Rhys RE). Gameplay You start in the upper left hand corner of the board. Tap the colored buttons along the bottom of the board to flood all ...
建立在安装 $ composer require noximo/php-colored-ascii-linechart用法简单输出: $ linechart = new Linechart ();echo $ linechart -> addMarkers ([ 1 , 2 , 3 , 4 , 5 , 6 ])-> addPoint ( 4 , 2 )-> chart ...
Comfort Reader ... Smart text processing and colored letter animation help you to recognize and understand text faster and better. Reading a book will seem just like watching a film - at the
标题中的“covid-colored-france-map”项目是一个用于展示法国COVID-19疫情相关数据的可视化工具,通过颜色编码的方式帮助人们理解不同地区疫情的严重程度。这个项目可能包括地图图像、交互式元素以及用于更新和展示...
A hybrid algorithm based on seeded region growing and k-means clustering was... Experimental results show that the proposed method is suitable for segmentation of multi-colored object, while conventional
随机游走matlab代码彩色随机游走 论文中提出的方法的实现: 作者:Yaowei ...Colored Random Walk}, author={Yan, Yaowei and Bian, Yuchen and Luo, Dongsheng and Lee, Dongwon and Zhang, Xiang}, booktitle
- 后缀为`.mexa64`的文件是编译过的MATLAB可执行文件,用于加速计算,如`bm3d_thr_colored_noise`、`bm3d_thr_sharpen_var`和`bm3d_wiener_video`可能分别对应彩色噪声去噪、变量阈值锐化和视频去噪的优化版本。...
双面,自发光,带透明通,带透明贴图,材质。可供参考使用。通过贴图,颜色,透明通道叠加实现。通过贴图,颜色,透明通道叠加实现。
数独色在此实验中,我创建了过度叠加的彩色数独。 该项目的灵感来自Alex Bellos的tridokus,我在他的《雪花贝壳之星:Numberland中的着色历险记》一书中发现了这个故事。入门先决条件您将需要安装以下软件包(如果...