Ja, klar. Sorry, war'nen Schnellschuss von unterwegs.
Hier also der Code. Wie gesagt, das merkwürdige ist, dass
das auf dem Eclipse-Simulator anstandslos läuft, bloß auf meinem
Handy siehts so komisch aus.
1import java.nio.ByteBuffer;
2import java.nio.ByteOrder;
3import java.nio.FloatBuffer;
4
5import javax.microedition.khronos.egl.EGLConfig;
6import javax.microedition.khronos.opengles.GL10;
7
8import com.ragingbudgie.test3.util.SystemUiHider;
9
10import android.annotation.TargetApi;
11import android.app.Activity;
12import android.graphics.Rect;
13import android.os.Build;
14import android.os.Bundle;
15import android.os.Handler;
16import android.view.MotionEvent;
17import android.view.View;
18import android.opengl.GLSurfaceView;
19
20
21public class MainActivity extends Activity implements GLSurfaceView.Renderer {
22
23 private GLSurfaceView m_GLView;
24 private Rect m_currentScreen;
25
26 private FloatBuffer m_Vertices;
27 private FloatBuffer m_Colors;
28
29 private Boolean m_Drawn;
30 private Boolean m_Created;
31
32 @Override
33 public void onDrawFrame(GL10 gl) {
34 // GLSurfaceView.Renderer
35
36 if (! m_Drawn) {
37 gl.glViewport(0, 0, m_currentScreen.width(), m_currentScreen.height());
38
39 // Vertices
40 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
41 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, m_Vertices);
42
43 //Colors
44 gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
45 gl.glColorPointer(4, GL10.GL_FLOAT, 0, m_Colors);
46
47 gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
48
49 m_Drawn = true;
50
51 }
52 }
53
54 @Override
55 public void onSurfaceChanged(GL10 gl, int width, int height) {
56 // GLSurfaceView.Renderer
57 if (m_currentScreen == null) {
58 m_currentScreen = new Rect();
59 }
60
61 m_currentScreen.set(0, 0, width, height);
62
63 }
64
65 @Override
66 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
67 // GLSurfaceView.Renderer
68
69 if(! m_Created){
70 m_Drawn = false;
71
72 ByteBuffer tempBuffer = ByteBuffer.allocateDirect( 3 * 3 * 4);
73
74 tempBuffer.order(ByteOrder.nativeOrder());
75
76 m_Vertices = tempBuffer.asFloatBuffer();
77
78 m_Vertices.put(-0.5f);
79 m_Vertices.put(-0.5f);
80 m_Vertices.put( 0.0f);
81
82 m_Vertices.put( 0.5f);
83 m_Vertices.put(-0.5f);
84 m_Vertices.put( 0.0f);
85
86 m_Vertices.put( 0.0f);
87 m_Vertices.put( 0.5f);
88 m_Vertices.put( 0.0f);
89
90 m_Vertices.rewind();
91
92
93 tempBuffer = ByteBuffer.allocateDirect( 3 * 4 * 4);
94
95 tempBuffer.order(ByteOrder.nativeOrder());
96
97 m_Colors = tempBuffer.asFloatBuffer();
98
99 m_Colors.put(1);
100 m_Colors.put(0);
101 m_Colors.put(0);
102 m_Colors.put(1);
103
104 m_Colors.put(0);
105 m_Colors.put(1);
106 m_Colors.put(0);
107 m_Colors.put(1);
108
109 m_Colors.put(0);
110 m_Colors.put(0);
111 m_Colors.put(1);
112 m_Colors.put(1);
113
114 m_Colors.rewind();
115
116 m_Created = true;
117 }
118 }
119
120 /* (non-Javadoc)
121 * @see android.app.Activity#onCreate(android.os.Bundle)
122 */
123 @Override
124 protected void onCreate(Bundle savedInstanceState) {
125 // TODO Auto-generated method stub
126 super.onCreate(savedInstanceState);
127
128 // Surfaceview erzeugen
129 m_GLView = new GLSurfaceView(this);
130 // Renderer-Callback registrieren (diese Klasse selbst)
131 m_GLView.setRenderer(this);
132
133 // GLSurfaceView als anzuzeigenden Inhalt setzen
134 this.setContentView( m_GLView );
135
136 m_Created = false;
137 }
138
139 /* (non-Javadoc)
140 * @see android.app.Activity#onPause()
141 */
142 @Override
143 protected void onPause() {
144 // TODO Auto-generated method stub
145 super.onPause();
146 m_GLView.onPause();
147 }
148
149 /* (non-Javadoc)
150 * @see android.app.Activity#onRestart()
151 */
152 @Override
153 protected void onRestart() {
154 // TODO Auto-generated method stub
155 super.onRestart();
156
157 }
158
159 /* (non-Javadoc)
160 * @see android.app.Activity#onResume()
161 */
162 @Override
163 protected void onResume() {
164 // TODO Auto-generated method stub
165 super.onResume();
166 m_GLView.onResume();
167 }
168
169 /* (non-Javadoc)
170 * @see android.app.Activity#onStart()
171 */
172 @Override
173 protected void onStart() {
174 // TODO Auto-generated method stub
175 super.onStart();
176
177 }
178
179 /* (non-Javadoc)
180 * @see android.app.Activity#onStop()
181 */
182 @Override
183 protected void onStop() {
184 // TODO Auto-generated method stub
185 super.onStop();
186
187 }
188
189
190}
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.