zoukankan
html css js c++ java
*How to use glCallLists in jogl<转>
package
glredbook10;
/** */
/**
* This program demonstrates some characters of a stroke (vector) font. The
* characters are represented by display lists, which are given numbers which
* correspond to the ASCII values of the characters. Use of glCallLists() is
* demonstrated.
*
*
@author
Kiet Le (Java port)
*/
import
java.awt.event.
*
;
import
javax.swing.
*
;
import
java.nio.
*
;
import
javax.media.opengl.
*
;
import
javax.media.opengl.glu.
*
;
import
com.sun.opengl.util.
*
;
public
class
stroke
extends
JFrame
implements
GLEventListener, KeyListener
{
private
GLU glu;
private
GLCapabilities caps;
private
GLCanvas canvas;
//
private
static
final
int
PT
=
1
;
private
static
final
int
STROKE
=
2
;
private
static
final
int
END
=
3
;
//
* C struct. Compare this to charpoint class.
//
typedef struct charpoint
//
{
//
GLfloat x, y;
//
int type;
//
} CP;
private
class
charpoint
{
public
float
x;
public
float
y;
public
int
type;
public
charpoint(
float
x,
float
y,
int
type)
{
this
.x
=
x;
this
.y
=
y;
this
.type
=
type;
}
}
//
* Saved here from original for you to see the difference
//
CP Adata[] =
//
{
//
{ 0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT},
//
{5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END}
//
};
charpoint Adata[]
=
{
new
charpoint(
0
,
0
, PT),
new
charpoint(
0
,
9
, PT),
//
new
charpoint(
1
,
10
, PT),
new
charpoint(
4
,
10
, PT),
//
new
charpoint(
5
,
9
, PT),
new
charpoint(
5
,
0
, STROKE),
//
new
charpoint(
0
,
5
, PT),
new
charpoint(
5
,
5
, END) }
;
charpoint Edata[]
=
{
new
charpoint(
5
,
0
, PT),
new
charpoint(
0
,
0
, PT),
//
new
charpoint(
0
,
10
, PT),
new
charpoint(
5
,
10
, STROKE),
//
new
charpoint(
0
,
5
, PT),
new
charpoint(
4
,
5
, END) }
;
charpoint Pdata[]
=
{
new
charpoint(
0
,
0
, PT),
new
charpoint(
0
,
10
, PT),
//
new
charpoint(
4
,
10
, PT),
new
charpoint(
5
,
9
, PT),
//
new
charpoint(
5
,
6
, PT),
new
charpoint(
4
,
5
, PT),
//
new
charpoint(
0
,
5
, END) }
;
charpoint Rdata[]
=
{
new
charpoint(
0
,
0
, PT),
new
charpoint(
0
,
10
, PT),
//
new
charpoint(
4
,
10
, PT),
new
charpoint(
5
,
9
, PT),
//
new
charpoint(
5
,
6
, PT),
new
charpoint(
4
,
5
, PT),
//
new
charpoint(
0
,
5
, STROKE),
new
charpoint(
3
,
5
, PT),
//
new
charpoint(
5
,
0
, END) }
;
charpoint Sdata[]
=
{
new
charpoint(
0
,
1
, PT),
new
charpoint(
1
,
0
, PT),
//
new
charpoint(
4
,
0
, PT),
new
charpoint(
5
,
1
, PT),
//
new
charpoint(
5
,
4
, PT),
new
charpoint(
4
,
5
, PT),
//
new
charpoint(
1
,
5
, PT),
new
charpoint(
0
,
6
, PT),
//
new
charpoint(
0
,
9
, PT),
new
charpoint(
1
,
10
, PT),
//
new
charpoint(
4
,
10
, PT),
new
charpoint(
5
,
9
, END) }
;
//
char *test1 = "A SPARE SERAPE APPEARS AS"; C char ptr to str
//
char *test2 = "APES PREPARE RARE PEPPERS";
private
String test1
=
"
A SPARE SERAPE APPEARS AS
"
;
//
String object
private
String test2
=
"
APES PREPARE RARE PEPPERS
"
;
public
stroke()
{
super
(
"
stroke
"
);
caps
=
new
GLCapabilities();
canvas
=
new
GLCanvas(caps);
canvas.addGLEventListener(
this
);
canvas.addKeyListener(
this
);
getContentPane().add(canvas);
}
public
void
run()
{
setSize(
440
,
120
);
setLocationRelativeTo(
null
);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(
true
);
canvas.requestFocusInWindow();
}
public
static
void
main(String[] args)
{
new
stroke().run();
}
/**/
/*
Create a display list for each of 6 characters
*/
public
void
init(GLAutoDrawable drawable)
{
GL gl
=
drawable.getGL();
glu
=
new
GLU();
int
base;
gl.glShadeModel(GL.GL_FLAT);
base
=
gl.glGenLists(
128
);
gl.glListBase(base);
gl.glNewList(base
+
'
A
'
, GL.GL_COMPILE);
drawLetter(gl, Adata);
gl.glEndList();
gl.glNewList(base
+
'
E
'
, GL.GL_COMPILE);
drawLetter(gl, Edata);
gl.glEndList();
gl.glNewList(base
+
'
P
'
, GL.GL_COMPILE);
drawLetter(gl, Pdata);
gl.glEndList();
gl.glNewList(base
+
'
R
'
, GL.GL_COMPILE);
drawLetter(gl, Rdata);
gl.glEndList();
gl.glNewList(base
+
'
S
'
, GL.GL_COMPILE);
drawLetter(gl, Sdata);
gl.glEndList();
gl.glNewList(base
+
'
'
, GL.GL_COMPILE);
gl.glTranslatef(
8.0f
,
0.0f
,
0.0f
);
gl.glEndList();
}
public
void
display(GLAutoDrawable drawable)
{
GL gl
=
drawable.getGL();
//
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glColor3f(
1.0f
,
1.0f
,
1.0f
);
gl.glPushMatrix();
gl.glScalef(
2.0f
,
2.0f
,
2.0f
);
gl.glTranslatef(
10.0f
,
30.0f
,
0.0f
);
this
.printStrokedString(gl, test1);
gl.glPopMatrix();
gl.glPushMatrix();
gl.glScalef(
2.0f
,
2.0f
,
2.0f
);
gl.glTranslatef(
10.0f
,
13.0f
,
0.0f
);
this
.printStrokedString(gl, test2);
gl.glPopMatrix();
gl.glFlush();
}
public
void
reshape(GLAutoDrawable drawable,
int
x,
int
y,
int
w,
int
h)
{
GL gl
=
drawable.getGL();
gl.glViewport(
0
,
0
, w, h);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(
0
, w,
0
, h);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public
void
displayChanged(GLAutoDrawable drawable,
boolean
modeChanged,
boolean
deviceChanged)
{
}
/**/
/*
* interprets the instructions from the array for that letter and renders the
* letter with line segments.
*/
private
void
drawLetter(GL gl, charpoint[] l)
{
int
i
=
0
;
gl.glBegin(GL.GL_LINE_STRIP);
while
(i
<
l.length)
{
switch
(l[i].type)
{
case
PT:
gl.glVertex2f(l[i].x, l[i].y);
break
;
case
STROKE:
gl.glVertex2f(l[i].x, l[i].y);
gl.glEnd();
gl.glBegin(GL.GL_LINE_STRIP);
break
;
case
END:
gl.glVertex2f(l[i].x, l[i].y);
gl.glEnd();
gl.glTranslatef(
8.0f
,
0.0f
,
0.0f
);
return
;
}
i
++
;
//
System.out.println(i+" ");
}
}
//
private void printStrokedString(char *s)
private
void
printStrokedString(GL gl, String s)
{
int
len
=
s.length();
ByteBuffer str
=
BufferUtil.newByteBuffer(len);
str.put(s.getBytes());
str.rewind();
gl.glCallLists(len, GL.GL_BYTE, str);
}
public
void
keyTyped(KeyEvent key)
{
}
public
void
keyPressed(KeyEvent key)
{
switch
(key.getKeyCode())
{
case
KeyEvent.VK_ESCAPE:
System.exit(
0
);
break
;
default
:
break
;
}
}
public
void
keyReleased(KeyEvent key)
{
}
}
查看全文
相关阅读:
docker 批量删除
ML
hdu 1465:不容易系列之一(递推入门题)
sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
sdut 2163:Identifiers(第二届山东省省赛原题,水题)
hdu 2108:Shape of HDU(计算几何,判断多边形是否是凸多边形,水题)
hrbustoj 1545:基础数据结构——顺序表(2)(数据结构,顺序表的实现及基本操作,入门题)
hdu 1312:Red and Black(DFS搜索,入门题)
hrbustoj 1429:凸多边形(计算几何,判断点是否在多边形内,二分法)
poj 1113:Wall(计算几何,求凸包周长)
原文地址:https://www.cnblogs.com/dwjaissk/p/705474.html
最新文章
MySQL数据分组Group By 和 Having
MySQL字段拼接Concat
MySQL的正则表达式的LIKE和REGEXP区别
SQL关于WHERE 的计算次序
MySQL中的排序(ORDER BY)
MySQL LIMIT的使用
MySQL 的 DISTINCT 应用于2列时
RabbitMQ 在Linux环境中的默认位置
kerl build error
cenos安装erlang
热门文章
linux 查看当前目录下包含某个字符串的文件
linux 查看系统信息
Docker镜像的导出和载入
Angular 2: 404 error occur when I refresh through the browser [duplicate]
abp框架angular 项目docker 手动部署到Linux环境中
docker 镜像的配置文件修改
vi vim 查找替换
pscp 命令---windows和linux之间互相拷贝文件的工具
In linux shell, How to cp/rm files by time?
Docker 容器镜像删除
Copyright © 2011-2022 走看看