求一个类似于windows画图的程序,300分相送-2 http://yuefeng.javaeye.com/blog/206706http://student.csdn.net/space.php?uid=121497&do=blog&id=17359http://developer.51cto.com/art/201001/180975.htmhttp://www.javaeye.com/topic/484289 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 android上用opengl画线/* ** ** Copyright 2006, The Android Open Source Project ** ** 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. */ #include <stdlib.h> #include <stdio.h> #include <EGL/egl.h> #include <GLES/gl.h> #include <GLES/glext.h> static void gluLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) { // See the OpenGL GLUT documentation for gluLookAt for a description // of the algorithm. We implement it in a straightforward way: float fx = centerX - eyeX; float fy = centerY - eyeY; float fz = centerZ - eyeZ; // Normalize f float rlf = 1.0f / sqrtf(fx*fx + fy*fy + fz*fz); fx *= rlf; fy *= rlf; fz *= rlf; // Normalize up float rlup = 1.0f / sqrtf(upX*upX + upY*upY + upZ*upZ); upX *= rlup; upY *= rlup; upZ *= rlup; // compute s = f x up (x means "cross product") float sx = fy * upZ - fz * upY; float sy = fz * upX - fx * upZ; float sz = fx * upY - fy * upX; // compute u = s x f float ux = sy * fz - sz * fy; float uy = sz * fx - sx * fz; float uz = sx * fy - sy * fx; float m[16] ; m[0] = sx; m[1] = ux; m[2] = -fx; m[3] = 0.0f; m[4] = sy; m[5] = uy; m[6] = -fy; m[7] = 0.0f; m[8] = sz; m[9] = uz; m[10] = -fz; m[11] = 0.0f; m[12] = 0.0f; m[13] = 0.0f; m[14] = 0.0f; m[15] = 1.0f; glMultMatrixf(m); glTranslatef(-eyeX, -eyeY, -eyeZ); } static void checkGLErrors() { GLenum error = glGetError(); if (error != GL_NO_ERROR) fprintf(stderr, "GL Error: 0x%04x\n", (int)error); } #define PI 3.1415926535897932f static void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) { GLfloat xmin, xmax, ymin, ymax; ymax = zNear * (GLfloat)tan(fovy * PI / 360); ymin = -ymax; xmin = ymin * aspect; xmax = ymax * aspect; glFrustumx((GLfixed)(xmin * 65536), (GLfixed)(xmax * 65536), (GLfixed)(ymin * 65536), (GLfixed)(ymax * 65536), (GLfixed)(zNear * 65536), (GLfixed)(zFar * 65536)); } void init(int width, int height) { // glEnable(GL_NORMALIZE); // glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); // glShadeModel(GL_FLAT); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glEnable(GL_LIGHT1); //glEnable(GL_LIGHT2); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glOrthof(0, (float)width, 0, (float)height, 0, 100); } static void prepareFrame(int width, int height) { glViewport(0, 0, width, height); glClearColorx((GLfixed)(0.1f * 65536), (GLfixed)(0.2f * 65536), (GLfixed)(0.3f * 65536), 0x10000); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // gluPerspective(45, (float)width / height, 0.5f, 150); /*glFrustumf(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 30.0f); */ glOrthof(0.0, width, 0.0, height, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } GLfloat vertices[][2] = { { 100.25f, 100.25f }, { 100.75f, 100.25f }, { 200.75f, 200.75f }, { 100.25f, 200.75f } }; GLubyte colors[][4] = { { 255, 0, 0, 80 }, { 255, 0, 0, 80 }, { 255, 0, 0, 80 }, { 255, 0, 0, 80 } }; int main(int argc, char** argv) { EGLint s_configAttribs[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_NONE }; EGLint numConfigs = -1; EGLint majorVersion; EGLint minorVersion; EGLConfig config; EGLContext context; EGLSurface surface; EGLint w, h; EGLDisplay dpy; dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(dpy, &majorVersion, &minorVersion); eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs); surface = eglCreateWindowSurface(dpy, config, android_createDisplaySurface(), NULL); context = eglCreateContext(dpy, config, NULL, NULL); eglMakeCurrent(dpy, surface, surface, context); eglQuerySurface(dpy, surface, EGL_WIDTH, &w); eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); GLint dim = w<h ? w : h; printf("w=%d, h=%d\n", w, h); init(w, h); int i=0, j=0; //while(1){ prepareFrame(w, h); /*r(i=0; i<4; i++){ vertices[i][0] += 1.0f; vertices[i][1] += 1.0f; }*/ glPushMatrix(); glVertexPointer(2, GL_FLOAT, 0, vertices); glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors); glDrawArrays(GL_LINES, 0, 4); glPopMatrix(); checkGLErrors(); eglSwapBuffers(dpy, surface); checkGLErrors(); //} return 0; } 放到frameworks/base/opengl/test下编译adb push 到emulator中运行 http://yuefeng.javaeye.com/blog/206706http://blog.csdn.net/arm10504/archive/2010/03/25/5415921.aspx 通过 OPENGL 代码上面的都给啦 http://blog.csdn.net/arm10504/archive/2010/03/25/5415921.aspx import android.app.Activity;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BlurMaskFilter;import android.graphics.Canvas;import android.graphics.MaskFilter;import android.graphics.Paint;import android.graphics.Path;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;public class Vi extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new MyView(this)); } public class MyView extends View { private Paint mPaint; private MaskFilter mBlur; private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mBitmapPaint; public MyView(Context c) { super(c); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL); mPaint.setMaskFilter(mBlur); mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(0xFFAAAAAA); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_start(float x, float y) { mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); // kill this so we don't double draw mPath.reset(); } @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_start(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } }} 安卓tabhost手势滑动效果问题 主题样式的问题 请教各位高手一个很奇怪的问题,在真机上adb install安装不上 如何监听数据库中一条记录的value是否有变化? 急求指导~~~ Android 系统自带日历,如何不注册Exchange账户就可以直接使用。也就是舍弃同步功能,只想正常使用其自带日历功能。有什么好的思路。 Android ARGB 格式 framebuffer 继承了一个VIEW,为什么不能用VIEW的PROTECTED变量呢 哪句话是执行打开端口的代码? 动态移动ImageView的位置 一个关于View的问题 DVI输出与LCD输出的切换实现。请教。
**
** Copyright 2006, The Android Open Source Project
**
** 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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
static void gluLookAt(float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ, float upX, float upY,
float upZ)
{
// See the OpenGL GLUT documentation for gluLookAt for a description
// of the algorithm. We implement it in a straightforward way:
float fx = centerX - eyeX;
float fy = centerY - eyeY;
float fz = centerZ - eyeZ;
// Normalize f
float rlf = 1.0f / sqrtf(fx*fx + fy*fy + fz*fz);
fx *= rlf;
fy *= rlf;
fz *= rlf;
// Normalize up
float rlup = 1.0f / sqrtf(upX*upX + upY*upY + upZ*upZ);
upX *= rlup;
upY *= rlup;
upZ *= rlup;
// compute s = f x up (x means "cross product")
float sx = fy * upZ - fz * upY;
float sy = fz * upX - fx * upZ;
float sz = fx * upY - fy * upX;
// compute u = s x f
float ux = sy * fz - sz * fy;
float uy = sz * fx - sx * fz;
float uz = sx * fy - sy * fx;
float m[16] ;
m[0] = sx;
m[1] = ux;
m[2] = -fx;
m[3] = 0.0f;
m[4] = sy;
m[5] = uy;
m[6] = -fy;
m[7] = 0.0f;
m[8] = sz;
m[9] = uz;
m[10] = -fz;
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
glMultMatrixf(m);
glTranslatef(-eyeX, -eyeY, -eyeZ);
}
static void checkGLErrors()
{
GLenum error = glGetError();
if (error != GL_NO_ERROR)
fprintf(stderr, "GL Error: 0x%04x\n", (int)error);
}
#define PI 3.1415926535897932f
static void gluPerspective(GLfloat fovy, GLfloat aspect,
GLfloat zNear, GLfloat zFar)
{
GLfloat xmin, xmax, ymin, ymax;
ymax = zNear * (GLfloat)tan(fovy * PI / 360);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustumx((GLfixed)(xmin * 65536), (GLfixed)(xmax * 65536),
(GLfixed)(ymin * 65536), (GLfixed)(ymax * 65536),
(GLfixed)(zNear * 65536), (GLfixed)(zFar * 65536));
}
void init(int width, int height)
{
// glEnable(GL_NORMALIZE);
// glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
// glShadeModel(GL_FLAT);
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
//glEnable(GL_LIGHT1);
//glEnable(GL_LIGHT2);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glOrthof(0, (float)width, 0, (float)height, 0, 100);
}
static void prepareFrame(int width, int height)
{
glViewport(0, 0, width, height);
glClearColorx((GLfixed)(0.1f * 65536),
(GLfixed)(0.2f * 65536),
(GLfixed)(0.3f * 65536), 0x10000);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluPerspective(45, (float)width / height, 0.5f, 150);
/*glFrustumf(0.0f, 1.0f,
0.0f, 1.0f,
1.0f, 30.0f);
*/
glOrthof(0.0, width, 0.0, height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
GLfloat vertices[][2] = {
{ 100.25f, 100.25f },
{ 100.75f, 100.25f },
{ 200.75f, 200.75f },
{ 100.25f, 200.75f }
};
GLubyte colors[][4] = {
{ 255, 0, 0, 80 },
{ 255, 0, 0, 80 },
{ 255, 0, 0, 80 },
{ 255, 0, 0, 80 }
};
int main(int argc, char** argv)
{
EGLint s_configAttribs[] = {
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_NONE
};
EGLint numConfigs = -1;
EGLint majorVersion;
EGLint minorVersion;
EGLConfig config;
EGLContext context;
EGLSurface surface;
EGLint w, h;
EGLDisplay dpy;
dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(dpy, &majorVersion, &minorVersion);
eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs);
surface = eglCreateWindowSurface(dpy, config,
android_createDisplaySurface(), NULL);
context = eglCreateContext(dpy, config, NULL, NULL);
eglMakeCurrent(dpy, surface, surface, context);
eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
GLint dim = w<h ? w : h;
printf("w=%d, h=%d\n", w, h);
init(w, h);
int i=0, j=0;
//while(1){
prepareFrame(w, h);
/*r(i=0; i<4; i++){
vertices[i][0] += 1.0f;
vertices[i][1] += 1.0f;
}*/
glPushMatrix();
glVertexPointer(2, GL_FLOAT, 0, vertices);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
glDrawArrays(GL_LINES, 0, 4);
glPopMatrix();
checkGLErrors();
eglSwapBuffers(dpy, surface);
checkGLErrors();
//}
return 0;
}
放到frameworks/base/opengl/test下编译adb push 到emulator中运行
http://blog.csdn.net/arm10504/archive/2010/03/25/5415921.aspx
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.MaskFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;public class Vi extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}
public class MyView extends View {
private Paint mPaint;
private MaskFilter mBlur;
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
public MyView(Context c) {
super(c);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0xFFFF0000);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(12);
mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
mPaint.setMaskFilter(mBlur);
mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
} @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
}
return true;
}
}
}