Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
itdan3344
stb
提交
1d18b23e
S
stb
项目概览
itdan3344
/
stb
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
stb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1d18b23e
编写于
2月 22, 2015
作者:
S
Sean Barrett
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace main.c & game.c with cave_main.c
上级
7add4d09
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
685 addition
and
382 deletion
+685
-382
tests/caveview/cave_main.c
tests/caveview/cave_main.c
+659
-0
tests/caveview/cave_render.c
tests/caveview/cave_render.c
+2
-2
tests/caveview/caveview.h
tests/caveview/caveview.h
+3
-0
tests/caveview/glext_list.h
tests/caveview/glext_list.h
+20
-20
tests/caveview/main.c
tests/caveview/main.c
+0
-359
tests/caveview/stb_gl.h
tests/caveview/stb_gl.h
+1
-1
未找到文件。
tests/caveview/
game
.c
→
tests/caveview/
cave_main
.c
浏览文件 @
1d18b23e
#include <windows.h>
#define _WIN32_WINNT 0x400
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
//#include "game.h"
#include <windows.h>
#define STB_GL_IMPLEMENTATION
#define STB_GLEXT_DEFINE "glext_list.h"
#include "stb_gl.h"
#define STB_DEFINE
#include "stb.h"
#include "caveview.h"
#include "sdl.h"
#include "SDL_opengl.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_GL_IMPLEMENTATION
#include "stb_gl.h"
#define STB_GLPROG_IMPLEMENTATION
#define STB_GLPROG_ARB_DEFINE_EXTENSIONS
#include "stb_glprog.h"
#include "stb_easy_font.h"
#include "stb_easy_font.h" // doesn't require an IMPLEMENTATION
#include "caveview.h"
char
*
game_name
=
"caveview"
;
...
...
@@ -26,43 +41,6 @@ GLuint interface_tex, logo_tex;
extern
int
screen_x
,
screen_y
;
// main.c
int
tex_w
,
tex_h
;
void
*
tex_data
;
GLuint
load_texture
(
char
*
filename
,
int
keep
)
{
GLuint
tex
;
tex_data
=
stbi_load
(
filename
,
&
tex_w
,
&
tex_h
,
NULL
,
4
);
if
(
tex_data
==
NULL
)
{
SDL_ShowSimpleMessageBox
(
SDL_MESSAGEBOX_ERROR
,
game_name
,
"Couldn't open image file."
,
NULL
);
exit
(
1
);
}
glGenTextures
(
1
,
&
tex
);
glBindTexture
(
GL_TEXTURE_2D
,
tex
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGBA
,
tex_w
,
tex_h
,
0
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
tex_data
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_NEAREST
);
if
(
!
keep
)
{
free
(
tex_data
);
tex_data
=
NULL
;
}
return
tex
;
}
static
void
init_graphics
(
void
)
{
//logo_tex = load_texture("sss_logo.png",0);
//interface_tex = load_texture("game_art.png",1);
texture_s_scale
=
1
.
0
f
/
tex_w
;
texture_t_scale
=
1
.
0
f
/
tex_h
;
}
void
print_string
(
float
x
,
float
y
,
char
*
text
,
float
r
,
float
g
,
float
b
)
{
static
char
buffer
[
99999
];
...
...
@@ -108,11 +86,9 @@ float rotate_view = 0.0;
void
init_game
(
void
)
{
init_graphics
();
//
init_graphics();
}
void
render_caves
(
float
pos
[
3
]);
void
camera_to_worldspace
(
float
world
[
3
],
float
cam_x
,
float
cam_y
,
float
cam_z
)
{
float
vec
[
3
]
=
{
cam_x
,
cam_y
,
cam_z
};
...
...
@@ -352,3 +328,332 @@ void draw_main(void)
glDisable
(
GL_CULL_FACE
);
draw_stats
();
}
#pragma warning(disable:4244; disable:4305; disable:4018)
#define SCALE 2
void
error
(
char
*
s
)
{
SDL_ShowSimpleMessageBox
(
SDL_MESSAGEBOX_ERROR
,
"Error"
,
s
,
NULL
);
exit
(
0
);
}
void
ods
(
char
*
fmt
,
...)
{
char
buffer
[
1000
];
va_list
va
;
va_start
(
va
,
fmt
);
vsprintf
(
buffer
,
fmt
,
va
);
va_end
(
va
);
SDL_Log
(
"%s"
,
buffer
);
}
#define TICKS_PER_SECOND 60
static
SDL_Window
*
window
;
extern
void
init_game
(
void
);
extern
void
draw_main
(
void
);
extern
void
process_tick
(
float
dt
);
extern
void
editor_init
(
void
);
void
draw
(
void
)
{
draw_main
();
SDL_GL_SwapWindow
(
window
);
}
static
int
initialized
=
0
;
static
float
last_dt
;
int
screen_x
,
screen_y
;
float
carried_dt
=
0
;
#define TICKRATE 60
int
raw_level_time
;
extern
void
init_game
(
void
);
extern
void
draw_main
(
void
);
float
global_timer
;
int
loopmode
(
float
dt
,
int
real
,
int
in_client
)
{
float
actual_dt
=
dt
;
float
jump_timer
=
dt
;
if
(
!
initialized
)
return
0
;
if
(
!
real
)
return
0
;
// don't allow more than 6 frames to update at a time
if
(
dt
>
0
.
075
)
dt
=
0
.
075
;
global_timer
+=
dt
;
carried_dt
+=
dt
;
while
(
carried_dt
>
1
.
0
/
TICKRATE
)
{
//update_input();
// if the player is dead, stop the sim
carried_dt
-=
1
.
0
/
TICKRATE
;
}
process_tick
(
dt
);
draw
();
return
0
;
}
static
int
quit
;
//int winproc(void *data, stbwingraph_event *e)
extern
int
editor_scale
;
extern
void
editor_key
(
enum
stbte_action
act
);
extern
int
controls
;
void
active_control_set
(
int
key
)
{
controls
|=
1
<<
key
;
}
void
active_control_clear
(
int
key
)
{
controls
&=
~
(
1
<<
key
);
}
extern
void
update_view
(
float
dx
,
float
dy
);
void
process_sdl_mouse
(
SDL_Event
*
e
)
{
update_view
((
float
)
e
->
motion
.
xrel
/
screen_x
,
(
float
)
e
->
motion
.
yrel
/
screen_y
);
}
void
process_event
(
SDL_Event
*
e
)
{
switch
(
e
->
type
)
{
case
SDL_MOUSEMOTION
:
process_sdl_mouse
(
e
);
break
;
case
SDL_MOUSEBUTTONDOWN
:
case
SDL_MOUSEBUTTONUP
:
case
SDL_MOUSEWHEEL
:
//stbte_mouse_sdl(edit_map, e, 1.0f/editor_scale,1.0f/editor_scale,0,0);
break
;
case
SDL_QUIT
:
quit
=
1
;
break
;
case
SDL_WINDOWEVENT
:
switch
(
e
->
window
.
event
)
{
case
SDL_WINDOWEVENT_SIZE_CHANGED
:
screen_x
=
e
->
window
.
data1
;
screen_y
=
e
->
window
.
data2
;
loopmode
(
0
,
1
,
0
);
break
;
}
break
;
case
SDL_TEXTINPUT
:
switch
(
e
->
text
.
text
[
0
])
{
#if 0
case 27: {
#if 0
int result;
SDL_ShowCursor(SDL_ENABLE);
if (MessageBox(e->handle, "Exit CLTT?", "CLTT", MB_OKCANCEL) == IDOK);
#endif
{
quit = 1;
break;
}
//SDL_ShowCursor(SDL_DISABLE);
break;
}
#endif
}
break
;
case
SDL_KEYDOWN
:
{
int
k
=
e
->
key
.
keysym
.
sym
;
int
s
=
e
->
key
.
keysym
.
scancode
;
SDL_Keymod
mod
;
mod
=
SDL_GetModState
();
if
(
k
==
SDLK_ESCAPE
)
{
#ifndef DO_EDITOR
quit
=
1
;
#endif
}
if
(
s
==
SDL_SCANCODE_D
)
active_control_set
(
0
);
if
(
s
==
SDL_SCANCODE_A
)
active_control_set
(
1
);
if
(
s
==
SDL_SCANCODE_W
)
active_control_set
(
2
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_set
(
3
);
if
(
k
==
SDLK_SPACE
)
active_control_set
(
4
);
if
(
s
==
SDL_SCANCODE_LCTRL
)
active_control_set
(
5
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_set
(
6
);
if
(
s
==
SDL_SCANCODE_D
)
active_control_set
(
7
);
#if 0
if (game_mode == GAME_editor) {
switch (k) {
case SDLK_RIGHT: editor_key(STBTE_scroll_right); break;
case SDLK_LEFT : editor_key(STBTE_scroll_left ); break;
case SDLK_UP : editor_key(STBTE_scroll_up ); break;
case SDLK_DOWN : editor_key(STBTE_scroll_down ); break;
}
switch (s) {
case SDL_SCANCODE_S: editor_key(STBTE_tool_select); break;
case SDL_SCANCODE_B: editor_key(STBTE_tool_brush ); break;
case SDL_SCANCODE_E: editor_key(STBTE_tool_erase ); break;
case SDL_SCANCODE_R: editor_key(STBTE_tool_rectangle ); break;
case SDL_SCANCODE_I: editor_key(STBTE_tool_eyedropper); break;
case SDL_SCANCODE_L: editor_key(STBTE_tool_link); break;
case SDL_SCANCODE_G: editor_key(STBTE_act_toggle_grid); break;
}
if ((e->key.keysym.mod & KMOD_CTRL) && !(e->key.keysym.mod & ~KMOD_CTRL)) {
switch (s) {
case SDL_SCANCODE_X: editor_key(STBTE_act_cut ); break;
case SDL_SCANCODE_C: editor_key(STBTE_act_copy ); break;
case SDL_SCANCODE_V: editor_key(STBTE_act_paste); break;
case SDL_SCANCODE_Z: editor_key(STBTE_act_undo ); break;
case SDL_SCANCODE_Y: editor_key(STBTE_act_redo ); break;
}
}
}
#endif
break
;
}
case
SDL_KEYUP
:
{
int
k
=
e
->
key
.
keysym
.
sym
;
int
s
=
e
->
key
.
keysym
.
scancode
;
if
(
s
==
SDL_SCANCODE_D
)
active_control_clear
(
0
);
if
(
s
==
SDL_SCANCODE_A
)
active_control_clear
(
1
);
if
(
s
==
SDL_SCANCODE_W
)
active_control_clear
(
2
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_clear
(
3
);
if
(
k
==
SDLK_SPACE
)
active_control_clear
(
4
);
if
(
s
==
SDL_SCANCODE_LCTRL
)
active_control_clear
(
5
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_clear
(
6
);
if
(
s
==
SDL_SCANCODE_D
)
active_control_clear
(
7
);
break
;
}
}
}
static
SDL_GLContext
*
context
;
static
float
getTimestep
(
float
minimum_time
)
{
float
elapsedTime
;
double
thisTime
;
static
double
lastTime
=
-
1
;
if
(
lastTime
==
-
1
)
lastTime
=
SDL_GetTicks
()
/
1000
.
0
-
minimum_time
;
for
(;;)
{
thisTime
=
SDL_GetTicks
()
/
1000
.
0
;
elapsedTime
=
(
float
)
(
thisTime
-
lastTime
);
if
(
elapsedTime
>=
minimum_time
)
{
lastTime
=
thisTime
;
return
elapsedTime
;
}
// @TODO: compute correct delay
SDL_Delay
(
1
);
}
}
void
APIENTRY
gl_debug
(
GLenum
source
,
GLenum
type
,
GLuint
id
,
GLenum
severity
,
GLsizei
length
,
const
GLchar
*
message
,
const
void
*
param
)
{
#if 0
if (severity == GL_DEBUG_SEVERITY_LOW_ARB)
return;
#endif
ods
(
"%s
\n
"
,
message
);
}
int
is_synchronous_debug
;
void
enable_synchronous
(
void
)
{
glEnable
(
GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
);
is_synchronous_debug
=
1
;
}
void
prepare_threads
(
void
);
//void stbwingraph_main(void)
int
SDL_main
(
int
argc
,
char
**
argv
)
{
SDL_Init
(
SDL_INIT_VIDEO
);
prepare_threads
();
SDL_GL_SetAttribute
(
SDL_GL_RED_SIZE
,
8
);
SDL_GL_SetAttribute
(
SDL_GL_GREEN_SIZE
,
8
);
SDL_GL_SetAttribute
(
SDL_GL_BLUE_SIZE
,
8
);
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_PROFILE_MASK
,
SDL_GL_CONTEXT_PROFILE_COMPATIBILITY
);
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_MAJOR_VERSION
,
3
);
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_MINOR_VERSION
,
1
);
#ifdef GL_DEBUG
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_FLAGS
,
SDL_GL_CONTEXT_DEBUG_FLAG
);
#endif
SDL_GL_SetAttribute
(
SDL_GL_MULTISAMPLESAMPLES
,
4
);
screen_x
=
1920
;
screen_y
=
1080
;
window
=
SDL_CreateWindow
(
"caveview"
,
SDL_WINDOWPOS_UNDEFINED
,
SDL_WINDOWPOS_UNDEFINED
,
screen_x
,
screen_y
,
SDL_WINDOW_OPENGL
|
SDL_WINDOW_RESIZABLE
);
if
(
!
window
)
error
(
"Couldn't create window"
);
context
=
SDL_GL_CreateContext
(
window
);
if
(
!
context
)
error
(
"Couldn't create context"
);
SDL_GL_MakeCurrent
(
window
,
context
);
// is this true by default?
// if (!IsDebuggerPresent())
SDL_SetRelativeMouseMode
(
SDL_TRUE
);
stbgl_initExtensions
();
#ifdef GL_DEBUG
if
(
glDebugMessageCallbackARB
)
{
glDebugMessageCallbackARB
(
gl_debug
,
NULL
);
enable_synchronous
();
}
#endif
SDL_GL_SetSwapInterval
(
0
);
// only when profiling
render_init
();
mesh_init
();
world_init
();
init_game
();
initialized
=
1
;
while
(
!
quit
)
{
SDL_Event
e
;
while
(
SDL_PollEvent
(
&
e
))
process_event
(
&
e
);
loopmode
(
getTimestep
(
0
.
0166
f
/
8
),
1
,
1
);
quit
=
quit
;
}
return
0
;
}
tests/caveview/cave_render.c
浏览文件 @
1d18b23e
...
...
@@ -772,7 +772,7 @@ void render_caves(float campos[3])
stbglUseProgram
(
main_prog
);
setup_uniforms
(
campos
);
// set uniforms to default values inefficiently
glActiveTextureARB
(
GL_TEXTURE2_ARB
);
glEnableVertexAttribArrayARB
(
0
);
stbglEnableVertexAttribArray
(
0
);
num_meshes_uploaded
=
0
;
update_meshes_from_render_thread
();
...
...
@@ -843,7 +843,7 @@ void render_caves(float campos[3])
}
}
glDisableVertexAttribArrayARB
(
0
);
stbglDisableVertexAttribArray
(
0
);
glBindBufferARB
(
GL_ARRAY_BUFFER_ARB
,
0
);
glActiveTextureARB
(
GL_TEXTURE0_ARB
);
...
...
tests/caveview/caveview.h
浏览文件 @
1d18b23e
...
...
@@ -38,6 +38,9 @@ extern void ods(char *fmt, ...); // output debug string
extern
void
reset_cache_size
(
int
size
);
extern
void
render_caves
(
float
pos
[
3
]);
#include "cave_parse.h" // fast_chunk
extern
fast_chunk
*
get_converted_fastchunk
(
int
chunk_x
,
int
chunk_y
);
...
...
tests/caveview/glext_list.h
浏览文件 @
1d18b23e
...
...
@@ -6,27 +6,27 @@ GLEXT(TexSubImage3D,TEXSUBIMAGE3D)
GLEXT
(
GenerateMipmap
,
GENERATEMIPMAP
)
GLARB
(
DebugMessageCallback
,
DEBUGMESSAGECALLBACK
)
GLARB
(
DeleteObject
,
DELETEOBJECT
)
GLARB
(
CreateProgramObject
,
CREATEPROGRAMOBJECT
)
GLARB
(
UseProgramObject
,
USEPROGRAMOBJECT
)
GLARB
(
CreateShaderObject
,
CREATESHADEROBJECT
)
GLARB
(
ShaderSource
,
SHADERSOURCE
)
GLARB
(
CompileShader
,
COMPILESHADER
)
GLARB
(
GetInfoLog
,
GETINFOLOG
)
GLARB
(
AttachObject
,
ATTACHOBJECT
)
GLARB
(
LinkProgram
,
LINKPROGRAM
)
GLARB
(
GetObjectParameteriv
,
GETOBJECTPARAMETERIV
)
GLARB
(
GetUniformLocation
,
GETUNIFORMLOCATION
)
GLARB
(
Uniform1i
,
UNIFORM1I
)
GLARB
(
Uniform1f
,
UNIFORM1F
)
GLARB
(
Uniform4f
,
UNIFORM4F
)
GLARB
(
Uniform2fv
,
UNIFORM2FV
)
GLARB
(
Uniform3fv
,
UNIFORM3FV
)
GLARB
(
Uniform4fv
,
UNIFORM4FV
)
GLARB
(
VertexAttribPointer
,
VERTEXATTRIBPOINTER
)
//
GLARB(DeleteObject,DELETEOBJECT)
//
GLARB(CreateProgramObject,CREATEPROGRAMOBJECT)
//
GLARB(UseProgramObject,USEPROGRAMOBJECT)
//
GLARB(CreateShaderObject,CREATESHADEROBJECT)
//
GLARB(ShaderSource,SHADERSOURCE)
//
GLARB(CompileShader,COMPILESHADER)
//
GLARB(GetInfoLog,GETINFOLOG)
//
GLARB(AttachObject,ATTACHOBJECT)
//
GLARB(LinkProgram,LINKPROGRAM)
//
GLARB(GetObjectParameteriv,GETOBJECTPARAMETERIV)
//
GLARB(GetUniformLocation,GETUNIFORMLOCATION)
////
GLARB(Uniform1i,UNIFORM1I)
//
GLARB(Uniform1f,UNIFORM1F)
//
GLARB(Uniform4f,UNIFORM4F)
//
GLARB(Uniform2fv,UNIFORM2FV)
//
GLARB(Uniform3fv,UNIFORM3FV)
//
GLARB(Uniform4fv,UNIFORM4FV)
//
GLARB(VertexAttribPointer,VERTEXATTRIBPOINTER)
GLCORE
(
VertexAttribIPointer
,
VERTEXATTRIBIPOINTER
)
GLARB
(
EnableVertexAttribArray
,
ENABLEVERTEXATTRIBARRAY
)
GLARB
(
DisableVertexAttribArray
,
DISABLEVERTEXATTRIBARRAY
)
//
GLARB(EnableVertexAttribArray,ENABLEVERTEXATTRIBARRAY)
//
GLARB(DisableVertexAttribArray,DISABLEVERTEXATTRIBARRAY)
GLEXT
(
BindFramebuffer
,
BINDFRAMEBUFFER
)
GLEXT
(
DeleteFramebuffers
,
DELETEFRAMEBUFFERS
)
...
...
tests/caveview/main.c
浏览文件 @
1d18b23e
#pragma warning(disable:4244; disable:4305; disable:4018)
#define _WIN32_WINNT 0x400
#include "sdl.h"
#include "sdl_mixer.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
//#include "game.h"
#include <windows.h>
#define STB_GLEXT_DEFINE "glext_list.h"
#include "stb_gl.h"
#define STB_DEFINE
#include "stb.h"
#include "caveview.h"
#define SCALE 2
void
error
(
char
*
s
)
{
SDL_ShowSimpleMessageBox
(
SDL_MESSAGEBOX_ERROR
,
"Error"
,
s
,
NULL
);
exit
(
0
);
}
void
ods
(
char
*
fmt
,
...)
{
char
buffer
[
1000
];
va_list
va
;
va_start
(
va
,
fmt
);
vsprintf
(
buffer
,
fmt
,
va
);
va_end
(
va
);
SDL_Log
(
"%s"
,
buffer
);
}
#define TICKS_PER_SECOND 60
static
SDL_Window
*
window
;
extern
void
init_game
(
void
);
extern
void
draw_main
(
void
);
extern
void
process_tick
(
float
dt
);
extern
void
editor_init
(
void
);
void
draw
(
void
)
{
draw_main
();
SDL_GL_SwapWindow
(
window
);
}
static
int
initialized
=
0
;
static
float
last_dt
;
int
screen_x
,
screen_y
;
float
carried_dt
=
0
;
#define TICKRATE 60
int
raw_level_time
;
extern
void
init_game
(
void
);
extern
void
draw_main
(
void
);
float
global_timer
;
int
loopmode
(
float
dt
,
int
real
,
int
in_client
)
{
float
actual_dt
=
dt
;
float
jump_timer
=
dt
;
if
(
!
initialized
)
return
0
;
if
(
!
real
)
return
0
;
// don't allow more than 6 frames to update at a time
if
(
dt
>
0
.
075
)
dt
=
0
.
075
;
global_timer
+=
dt
;
carried_dt
+=
dt
;
while
(
carried_dt
>
1
.
0
/
TICKRATE
)
{
//update_input();
// if the player is dead, stop the sim
carried_dt
-=
1
.
0
/
TICKRATE
;
}
process_tick
(
dt
);
draw
();
return
0
;
}
static
int
quit
;
//int winproc(void *data, stbwingraph_event *e)
extern
int
editor_scale
;
extern
void
editor_key
(
enum
stbte_action
act
);
extern
int
controls
;
void
active_control_set
(
int
key
)
{
controls
|=
1
<<
key
;
}
void
active_control_clear
(
int
key
)
{
controls
&=
~
(
1
<<
key
);
}
extern
void
update_view
(
float
dx
,
float
dy
);
void
process_sdl_mouse
(
SDL_Event
*
e
)
{
update_view
((
float
)
e
->
motion
.
xrel
/
screen_x
,
(
float
)
e
->
motion
.
yrel
/
screen_y
);
}
void
process_event
(
SDL_Event
*
e
)
{
switch
(
e
->
type
)
{
case
SDL_MOUSEMOTION
:
process_sdl_mouse
(
e
);
break
;
case
SDL_MOUSEBUTTONDOWN
:
case
SDL_MOUSEBUTTONUP
:
case
SDL_MOUSEWHEEL
:
//stbte_mouse_sdl(edit_map, e, 1.0f/editor_scale,1.0f/editor_scale,0,0);
break
;
case
SDL_QUIT
:
quit
=
1
;
break
;
case
SDL_WINDOWEVENT
:
switch
(
e
->
window
.
event
)
{
case
SDL_WINDOWEVENT_SIZE_CHANGED
:
screen_x
=
e
->
window
.
data1
;
screen_y
=
e
->
window
.
data2
;
loopmode
(
0
,
1
,
0
);
break
;
}
break
;
case
SDL_TEXTINPUT
:
switch
(
e
->
text
.
text
[
0
])
{
#if 0
case 27: {
#if 0
int result;
SDL_ShowCursor(SDL_ENABLE);
if (MessageBox(e->handle, "Exit CLTT?", "CLTT", MB_OKCANCEL) == IDOK);
#endif
{
quit = 1;
break;
}
//SDL_ShowCursor(SDL_DISABLE);
break;
}
#endif
}
break
;
case
SDL_KEYDOWN
:
{
int
k
=
e
->
key
.
keysym
.
sym
;
int
s
=
e
->
key
.
keysym
.
scancode
;
SDL_Keymod
mod
;
mod
=
SDL_GetModState
();
if
(
k
==
SDLK_ESCAPE
)
{
#ifndef DO_EDITOR
quit
=
1
;
#endif
}
if
(
s
==
SDL_SCANCODE_D
)
active_control_set
(
0
);
if
(
s
==
SDL_SCANCODE_A
)
active_control_set
(
1
);
if
(
s
==
SDL_SCANCODE_W
)
active_control_set
(
2
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_set
(
3
);
if
(
k
==
SDLK_SPACE
)
active_control_set
(
4
);
if
(
s
==
SDL_SCANCODE_LCTRL
)
active_control_set
(
5
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_set
(
6
);
if
(
s
==
SDL_SCANCODE_D
)
active_control_set
(
7
);
#if 0
if (game_mode == GAME_editor) {
switch (k) {
case SDLK_RIGHT: editor_key(STBTE_scroll_right); break;
case SDLK_LEFT : editor_key(STBTE_scroll_left ); break;
case SDLK_UP : editor_key(STBTE_scroll_up ); break;
case SDLK_DOWN : editor_key(STBTE_scroll_down ); break;
}
switch (s) {
case SDL_SCANCODE_S: editor_key(STBTE_tool_select); break;
case SDL_SCANCODE_B: editor_key(STBTE_tool_brush ); break;
case SDL_SCANCODE_E: editor_key(STBTE_tool_erase ); break;
case SDL_SCANCODE_R: editor_key(STBTE_tool_rectangle ); break;
case SDL_SCANCODE_I: editor_key(STBTE_tool_eyedropper); break;
case SDL_SCANCODE_L: editor_key(STBTE_tool_link); break;
case SDL_SCANCODE_G: editor_key(STBTE_act_toggle_grid); break;
}
if ((e->key.keysym.mod & KMOD_CTRL) && !(e->key.keysym.mod & ~KMOD_CTRL)) {
switch (s) {
case SDL_SCANCODE_X: editor_key(STBTE_act_cut ); break;
case SDL_SCANCODE_C: editor_key(STBTE_act_copy ); break;
case SDL_SCANCODE_V: editor_key(STBTE_act_paste); break;
case SDL_SCANCODE_Z: editor_key(STBTE_act_undo ); break;
case SDL_SCANCODE_Y: editor_key(STBTE_act_redo ); break;
}
}
}
#endif
break
;
}
case
SDL_KEYUP
:
{
int
k
=
e
->
key
.
keysym
.
sym
;
int
s
=
e
->
key
.
keysym
.
scancode
;
if
(
s
==
SDL_SCANCODE_D
)
active_control_clear
(
0
);
if
(
s
==
SDL_SCANCODE_A
)
active_control_clear
(
1
);
if
(
s
==
SDL_SCANCODE_W
)
active_control_clear
(
2
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_clear
(
3
);
if
(
k
==
SDLK_SPACE
)
active_control_clear
(
4
);
if
(
s
==
SDL_SCANCODE_LCTRL
)
active_control_clear
(
5
);
if
(
s
==
SDL_SCANCODE_S
)
active_control_clear
(
6
);
if
(
s
==
SDL_SCANCODE_D
)
active_control_clear
(
7
);
break
;
}
}
}
static
SDL_GLContext
*
context
;
static
float
getTimestep
(
float
minimum_time
)
{
float
elapsedTime
;
double
thisTime
;
static
double
lastTime
=
-
1
;
if
(
lastTime
==
-
1
)
lastTime
=
SDL_GetTicks
()
/
1000
.
0
-
minimum_time
;
for
(;;)
{
thisTime
=
SDL_GetTicks
()
/
1000
.
0
;
elapsedTime
=
(
float
)
(
thisTime
-
lastTime
);
if
(
elapsedTime
>=
minimum_time
)
{
lastTime
=
thisTime
;
return
elapsedTime
;
}
// @TODO: compute correct delay
SDL_Delay
(
1
);
}
}
void
APIENTRY
gl_debug
(
GLenum
source
,
GLenum
type
,
GLuint
id
,
GLenum
severity
,
GLsizei
length
,
const
GLchar
*
message
,
const
void
*
param
)
{
#if 0
if (severity == GL_DEBUG_SEVERITY_LOW_ARB)
return;
#endif
ods
(
"%s
\n
"
,
message
);
}
extern
void
do_music
(
int16
*
stream
,
int
samples
);
extern
void
foo
(
void
);
void
render_init
(
void
);
int
is_synchronous_debug
;
void
enable_synchronous
(
void
)
{
glEnable
(
GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
);
is_synchronous_debug
=
1
;
}
void
prepare_threads
(
void
);
//void stbwingraph_main(void)
int
SDL_main
(
int
argc
,
char
**
argv
)
{
SDL_Init
(
SDL_INIT_VIDEO
);
prepare_threads
();
Mix_Init
(
0
);
Mix_OpenAudio
(
48000
,
AUDIO_S16SYS
,
2
,
1024
);
// 1024 bytes = 256 samples =
SDL_GL_SetAttribute
(
SDL_GL_RED_SIZE
,
8
);
SDL_GL_SetAttribute
(
SDL_GL_GREEN_SIZE
,
8
);
SDL_GL_SetAttribute
(
SDL_GL_BLUE_SIZE
,
8
);
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_PROFILE_MASK
,
SDL_GL_CONTEXT_PROFILE_COMPATIBILITY
);
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_MAJOR_VERSION
,
3
);
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_MINOR_VERSION
,
1
);
#ifdef GL_DEBUG
SDL_GL_SetAttribute
(
SDL_GL_CONTEXT_FLAGS
,
SDL_GL_CONTEXT_DEBUG_FLAG
);
#endif
SDL_GL_SetAttribute
(
SDL_GL_MULTISAMPLESAMPLES
,
4
);
screen_x
=
1920
;
screen_y
=
1080
;
window
=
SDL_CreateWindow
(
"caveview"
,
SDL_WINDOWPOS_UNDEFINED
,
SDL_WINDOWPOS_UNDEFINED
,
screen_x
,
screen_y
,
SDL_WINDOW_OPENGL
|
SDL_WINDOW_RESIZABLE
);
if
(
!
window
)
error
(
"Couldn't create window"
);
context
=
SDL_GL_CreateContext
(
window
);
if
(
!
context
)
error
(
"Couldn't create context"
);
SDL_GL_MakeCurrent
(
window
,
context
);
// is this true by default?
// if (!IsDebuggerPresent())
SDL_SetRelativeMouseMode
(
SDL_TRUE
);
stbgl_initExtensions
();
#ifdef GL_DEBUG
if
(
glDebugMessageCallbackARB
)
{
glDebugMessageCallbackARB
(
gl_debug
,
NULL
);
enable_synchronous
();
}
#endif
SDL_GL_SetSwapInterval
(
0
);
// only when profiling
render_init
();
mesh_init
();
world_init
();
init_game
();
//editor_init();
initialized
=
1
;
while
(
!
quit
)
{
SDL_Event
e
;
while
(
SDL_PollEvent
(
&
e
))
process_event
(
&
e
);
loopmode
(
getTimestep
(
0
.
0166
f
/
8
),
1
,
1
);
quit
=
quit
;
}
//music_end();
return
0
;
}
tests/caveview/stb_gl.h
浏览文件 @
1d18b23e
...
...
@@ -344,7 +344,7 @@ void stbgl_Perspective(float zoom, float max_hfov, float max_vfov, float znear,
}
else
{
vfov
=
(
float
)
atan
((
unit_height
/
2
)
/
zoom
);
}
vfov
=
stbgl_rad2deg
(
vfov
*
2
);
vfov
=
(
float
)
stbgl_rad2deg
(
vfov
*
2
);
gluPerspective
(
vfov
,
aspect
,
znear
,
zfar
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录