Author:
theagentd (posted
2013-01-10 10:25:50 , viewed 412 times)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import org .lwjgl .LWJGLException ;
import org .lwjgl .opengl .Display ;
import org .lwjgl .opengl .DisplayMode ;
import org .lwjgl .opengl .GL11 ;
import org .lwjgl .opengl .PixelFormat ;
import static org .lwjgl .opengl .GL11 .*;
public class GameWindow
{
class player
{
double x ;
double y ;
double prevX ;
double prevY ;
double viewX ;
double viewY ;
double size ;
player ()
{
x = 25 ;
y = 150 ;
prevX = x ;
prevY = y ;
viewX = x ;
viewY = y ;
size = 64 ;
}
}
player p = new player ();
public static void main (String [] argv )
{
GameWindow gWin = new GameWindow ();
gWin .run ();
}
public void run ()
{
try
{
Display .setDisplayMode (new DisplayMode (800 , 600 ));
Display .setVSyncEnabled (true );
Display .create ();
}
catch (LWJGLException e )
{
int j = GL11 .glGetError ();
System .out .println ("ERROR : " + j );
System .exit (0 );
}
glClearColor (0.0f , 0.0f , 0.0f , 1.0f );
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode (GL_PROJECTION );
glLoadIdentity ();
glOrtho (0 , 800 , 600 , 0 , -1 , 1 );
glMatrixMode (GL_MODELVIEW );
glLoadIdentity ();
int err = GL11 .glGetError ();
if (err != GL_NO_ERROR )
{
System .out .println ("err" );
System .exit (0 );
}
long updateTime = 1000 * 1000 * 1000 / 25 ;
int loops = 0 ;
int MaxLoops = 10 ;
int frames = 0 ;
long gameClock = System .nanoTime ();
long lastFrame = gameClock ;
while (!Display .isCloseRequested ())
{
frames ++;
loops = 0 ;
while ((System .nanoTime () >= gameClock ) && (loops < MaxLoops ))
{
p .prevX = p .x ;
if (p .x > 800 )
{
p .x = 0 - p .size ;
p .prevX = 0 - p .size ;
}
else
p .x += 7 ;
gameClock += updateTime ;
loops ++;
}
double alpha = (double )(System .nanoTime () - gameClock + updateTime ) / updateTime ;
System .out .println (alpha );
p .viewX = p .prevX + alpha * (p .x - p .prevX );
p .viewY = p .prevY + alpha * (p .y - p .prevY );
if (System .currentTimeMillis () - lastFrame > 1000 )
{
Display .setTitle ("FPS : " + frames );
frames = 0 ;
lastFrame += 1000 ;
}
draw ();
Display .update ();
}
Display .destroy ();
}
void draw ()
{
glClear (GL_COLOR_BUFFER_BIT );
glBegin (GL_QUADS );
glColor3f (1 , 1 , 1 );
glVertex2d (0 , 0 );
glVertex2d (800 , 0 );
glVertex2d (800 , 600 );
glVertex2d (0 , 600 );
glEnd ();
glBegin (GL_QUADS );
glColor3f (0 , 0 , 0 );
glVertex2d (p .viewX , p .viewY );
glVertex2d (p .viewX + p .size , p .viewY );
glVertex2d (p .viewX + p .size , p .viewY + p .size );
glVertex2d (p .viewX , p .viewY + p .size );
glEnd ();
}
}
Special syntax:
To highlight a line (yellow background), prefix it with '@@'
To indicate that a line should be removed (red background), prefix it with '-'
To indicate that a line should be added (green background), prefix it with '+'
To post multiple snippets, seperate them by '~~~~'
ivj94
(586 views)
2018-03-24 14:47:39
ivj94
(49 views)
2018-03-24 14:46:31
ivj94
(383 views)
2018-03-24 14:43:53
Solater
(63 views)
2018-03-17 05:04:08
nelsongames
(110 views)
2018-03-05 17:56:34
Gornova
(159 views)
2018-03-02 22:15:33
buddyBro
(704 views)
2018-02-28 16:59:18
buddyBro
(93 views)
2018-02-28 16:45:17
xxMrPHDxx
(494 views)
2017-12-31 17:17:51
xxMrPHDxx
(734 views)
2017-12-31 17:15:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org