在写SDL中的问题。

在写SDL中的问题。,第1张

#i nclude <stdio.h>

#i nclude <dos.h>

#i nclude <conio.h>

#i nclude <graphics.h>

#i nclude <stdlib.h>

#ifdef __cplusplus

#define __CPPARGS ...

#else

#define __CPPARGS

#endif

#define MINBOXSIZE 15 /* 最小方块的尺寸 */

#define BGCOLOR 7 /* 背景着色 */

#define GX 200

#define GY 10

#define SJNUM 10000 /* 每当玩家打到一万分等级加一级*/

/* 按键码*/

#define VK_LEFT 0x4b00

#define VK_RIGHT 0x4d00

#define VK_DOWN 0x5000

#define VK_UP 0x4800

#define VK_HOME 0x4700

#define VK_END 0x4f00

#define VK_SPACE 0x3920

#define VK_ESC 0x011b

#define VK_ENTER 0x1c0d

/* 定义俄罗斯方块的方向(我定义他为4种)*/

#define F_DONG 0

#define F_NAN 1

#define F_XI 2

#define F_BEI 3

#define NEXTCOL 20 /* 要出的下一个方块的纵坐标*/

#define NEXTROW 12 /* 要出的下一个方块的横从标*/

#define MAXROW 14 /* 游戏屏幕大小*/

#define MAXCOL 20

#define SCCOL 100 /*游戏屏幕大显示器上的相对位置*/

#define SCROW 60

int gril[22][16]/* 游戏屏幕坐标*/

int col=1,row=7/* 当前方块的横纵坐标*/

int boxfx=0,boxgs=0/* 当前寺块的形壮和方向*/

int nextboxfx=0,nextboxgs=0,maxcol=22/*下一个方块的形壮和方向*/

int minboxcolor=6,nextminboxcolor=6

int num=0/*游戏分*/

int dj=0,gamedj[10]={18,16,14,12,10,8,6,4,2,1}/* 游戏等级*/

/* 以下我用了一个3维数组来纪录方块的最初形状和方向*/

int boxstr[7][4][16]={{

{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},

{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0},

{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},

{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0}},

{

{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},

{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0},

{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},

{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0}},

{

{1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0},

{1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0},

{1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0},

{0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0}},

{

{1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0},

{1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},

{0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},

{1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0}},

{

{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},

{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},

{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},

{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}},

{

{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0},

{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0},

{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0},

{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0}},

{

{0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0},

{1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0},

{0,1,0,0,1,1,1,0,0,0,0,0.0,0,0,0},

{0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0}}

}

/* 随机得到当前方块和下一个方块的形状和方向*/

void boxrad(){

minboxcolor=nextminboxcolor

boxgs=nextboxgs

boxfx=nextboxfx

nextminboxcolor=random(14)+1

if(nextminboxcolor==4||nextminboxcolor==7||nextminboxcolor==8)

nextminboxcolor=9

nextboxfx=F_DONG

nextboxgs=random(7)

}

/*初始化图形模试*/

void init(int gdrive,int gmode){

int errorcode

initgraph(&gdrive,&gmode,"e:\tc")

errorcode=graphresult()

if(errorcode!=grOk){

printf("error of: %s",grapherrormsg(errorcode))

exit(1)

}

}

/* 在图形模式下的清屏 */

void cls()

{

setfillstyle(SOLID_FILL,0)

setcolor(0)

bar(0,0,640,480)

}

/*在图形模式下的高级清屏*/

void clscr(int a,int b,int c,int d,int color){

setfillstyle(SOLID_FILL,color)

setcolor(color)

bar(a,b,c,d)

}

/*最小方块的绘制*/

void minbox(int asc,int bsc,int color,int bdcolor){

int a=0,b=0

a=SCCOL+asc

b=SCROW+bsc

clscr(a+1,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE,color)

if(color!=BGCOLOR){

setcolor(bdcolor)

line(a+1,b+1,a-1+MINBOXSIZE,b+1)

line(a+1,b+1,a+1,b-1+MINBOXSIZE)

line(a-1+MINBOXSIZE,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE)

line(a+1,b-1+MINBOXSIZE,a-1+MINBOXSIZE,b-1+MINBOXSIZE)

}

}

/*游戏中出现的文字*/

void txt(int a,int b,char *txt,int font,int color){

setcolor(color)

settextstyle(0,0,font)

outtextxy(a,b,txt)

}

/*windows 绘制*/

void win(int a,int b,int c,int d,int bgcolor,int bordercolor){

clscr(a,b,c,d,bgcolor)

setcolor(bordercolor)

line(a,b,c,b)

line(a,b,a,d)

line(a,d,c,d)

line(c,b,c,d)

}

/* 当前方块的绘制*/

void funbox(int a,int b,int color,int bdcolor){

int i,j

int boxz[4][4]

for(i=0i<16i++)

boxz[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

if(boxz[i][j]==1)

minbox((j+row+a)*MINBOXSIZE,(i+col+b)*MINBOXSIZE,color,bdcolor)

}

/*下一个方块的绘制*/

void nextfunbox(int a,int b,int color,int bdcolor){

int i,j

int boxz[4][4]

for(i=0i<16i++)

boxz[i/4][i%4]=boxstr[nextboxgs][nextboxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

if(boxz[i][j]==1)

minbox((j+a)*MINBOXSIZE,(i+b)*MINBOXSIZE,color,bdcolor)

}

/*时间中断定义*/

#define TIMER 0x1c

int TimerCounter=0

void interrupt ( *oldhandler)(__CPPARGS)

void interrupt newhandler(__CPPARGS){

TimerCounter++

oldhandler()

}

void SetTimer(void interrupt (*IntProc)(__CPPARGS)){

oldhandler=getvect(TIMER)

disable()

setvect(TIMER,IntProc)

enable()

}

/*由于游戏的规则,消掉都有最小方块的一行*/

void delcol(int a){

int i,j

for(i=ai>1i--)

for(j=1j<15j++){

minbox(j*MINBOXSIZE,i*MINBOXSIZE,BGCOLOR,BGCOLOR)

gril[i][j]=gril[i-1][j]

if(gril[i][j]==1)

minbox(j*MINBOXSIZE,i*MINBOXSIZE,minboxcolor,0)

}

}

/*消掉所有都有最小方块的行*/

void delete(){

int i,j,zero,delgx=0

char *nm="00000"

for(i=1i<21i++){

zero=0

for(j=1j<15j++)

if(gril[i][j]==0)

zero=1

if(zero==0){

delcol(i)

delgx++

}

}

num=num+delgx*delgx*10

dj=num/10000

sprintf(nm,"%d",num)

clscr(456,173,500,200,4)

txt(456,173,"Number:",1,15)

txt(456,193,nm,1,15)

}

/*时间中断结束*/

void KillTimer(){

disable()

setvect(TIMER,oldhandler)

enable()

}

/* 测试当前方块是否可以向下落*/

int downok(){

int i,j,k=1,a[4][4]

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

if(a[i][j] &&gril[col+i+1][row+j])

k=0

return(k)

}

/* 测试当前方块是否可以向左行*/

int leftok(){

int i,j,k=1,a[4][4]

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

if(a[i][j] &&gril[col+i][row+j-1])

k=0

return(k)

}

/* 测试当前方块是否可以向右行*/

int rightok(){

int i,j,k=1,a[4][4]

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

if(a[i][j] &&gril[col+i][row+j+1])

k=0

return(k)

}

/* 测试当前方块是否可以变形*/

int upok(){

int i,j,k=1,a[4][4]

for(i=0i<4i++)

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx+1][i]

for(i=3i>=0i--)

for(j=3j>=0j--)

if(a[i][j] &&gril[col+i][row+j])

k=0

return(k)

}

/*当前方块落下之后,给屏幕坐标作标记*/

void setgril(){

int i,j,a[4][4]

funbox(0,0,minboxcolor,0)

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

if(a[i][j])

gril[col+i][row+j]=1

col=1row=7

}

/*游戏结束*/

void gameover(){

int i,j

for(i=20i>0i--)

for(j=1j<15j++)

minbox(j*MINBOXSIZE,i*MINBOXSIZE,2,0)

txt(103,203,"Game Over",3,10)

}

/*按键的设置*/

void call_key(int keyx){

switch(keyx){

case VK_DOWN: { /*下方向键,横坐标加一。*/

if(downok()){

col++

funbox(0,0,minboxcolor,0)}

else{

funbox(0,0,minboxcolor,0)

setgril()

nextfunbox(NEXTCOL,NEXTROW,4,4)

boxrad()

nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0)

delete()

}

break

}

case VK_UP: { /*上方向键,方向形状旋转90度*/

if(upok())

boxfx++

if(boxfx>3)

boxfx=0

funbox(0,0,minboxcolor,0)

break

}

case VK_LEFT:{ /*左方向键,纵坐标减一*/

if(leftok())

row--

funbox(0,0,minboxcolor,0)

break

}

case VK_RIGHT:{ /*右方向键,纵坐标加一*/

if(rightok())

row++

funbox(0,0,minboxcolor,0)

break

}

case VK_SPACE: /*空格键,直接落到最后可以落到的们置*/

while(downok())

col++

funbox(0,0,minboxcolor,0)

setgril()

nextfunbox(NEXTCOL,NEXTROW,4,4)

boxrad()

nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0)

delete()

break

default:

{

txt(423,53,"worng key!",1,4)

txt(428,80,"Plese Enter Anly Key AG!",1,4)

getch()

clscr(420,50,622,97,BGCOLOR)

}

}

}

/*时间中断开始*/

void timezd(void){

int key

SetTimer(newhandler)

boxrad()

nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0)

for(){

if(bioskey(1)){

key=bioskey(0)

funbox(0,0,BGCOLOR,BGCOLOR)

if(key==VK_ESC)

break

call_key(key)

}

if(TimerCounter>gamedj[dj]){

TimerCounter=0

if(downok()){

funbox(0,0,BGCOLOR,BGCOLOR)

col++

funbox(0,0,minboxcolor,0)

}

else {

if(col==1){

gameover()

getch()

break

}

setgril()

delete()

funbox(0,0,minboxcolor,0)

col=1row=7

funbox(0,0,BGCOLOR,BGCOLOR)

nextfunbox(NEXTCOL,NEXTROW,4,4)

boxrad()

nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0)

}

}

}

}

/*主程序开始*/

void main(void){

int i,j

char *nm="00000"

init(VGA,VGAHI)

cls()

/*屏幕坐标初始化*/

for(i=0i<=MAXCOL+1i++)

for(j=0j<=MAXROW+1j++)

gril[i][j]=0

for(i=0i<=MAXCOL+1i++) {

gril[i][0]=1

gril[i][15]=1

}

for(j=1j<=MAXROWj++){

gril[0][j]=1

gril[21][j]=1

}

clscr(0,0,640,480,15)

win(1,1,639,479,4,15)

win(SCCOL+MINBOXSIZE-2,SCROW+MINBOXSIZE-2,SCCOL+15*MINBOXSIZE+2,SCROW+21*MINBOXSIZE+2,BGCOLOR,0)

nextboxgs=random(8)

nextboxfx=random(4)

sprintf(nm,"%d",num)

txt(456,173,"Number:",1,15)

txt(456,193,nm,1,15)

txt(456,243,"Next Box:",1,15)

timezd()

KillTimer()

closegraph()

}

官网: https://www.glfw.org/

是OpenGL的一个地方方苦,支持OpenGL、ES、Vulkan,支持多窗口高DPI 和gamma ramps,支持常用外设。开源用C实现的,要用zlib和libpng库。

首先包含头头文件

在glfw使用之前先要出世,初始化只要是检查环境是不是支持。

GLFWAPI int glfwInit(void)

初始化GLFW库,在应用称许执行之前要先调用这个函数,对应的终止函数是glfwTerminate,在应用程序结束之前要调用glfwTerminate,成功返回GLFW_TRUE

GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback)

设置错误回调函数,当一个错误发生时回调用错误码和一段描述信息。回调函数的个是如下:

GLFWAPI void glfwWindowHint(int hint, int value)

GLFWAPI void glfwWindowHintString(int hint, const char* value)

设置window的hints值,在glfwCreatewindow时生效,设置之后不会改变,知道遇到函数glfwDefaultWindowHints或GLFW终止。这个函数只能设置整形值,字符串的值通过glfwWindowHintString来设置。另外它不检查设置的值是否有效,在glfwCreateWindow的时候才会报.

GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share)

创建GL/ES的上下文,参数指定了上下文如何创建,成功创建不影响当前上下文。

GLFWAPI void glfwMakeContextCurrent(GLFWwindow* window)

指定当前GL/ES上下文

GLFWAPI int glfwWindowShouldClose(GLFWwindow* window)

检查指定window的关闭状态.

先设置事件回调函数,输入事件比较多。

渲染的时候framebuffer的size可以设置和viewport一样大,也可以设置framebuffer size的回调函数。

GLFWAPI double glfwGetTime(void)

获取GLFW的时间,以秒为单位

GLFWAPI void glfwSetTime(double time)

设置GLFW的时间,以秒为单位,小于等于18446744073.0

GLFWAPI uint64_t glfwGetTimerValue(void)

获取raw timer的值,单位1 / frequency seconds

GLFWAPI uint64_t glfwGetTimerFrequency(void)

获取帧率单位是Hz

GLFWAPI void glfwSwapBuffers(GLFWwindow* window)

交换窗口的前后缓冲区,如果交换间隔大于0,交换缓冲区之前GPU驱动会等待specified number of screen updates

GLFWAPI void glfwSwapInterval(int interval)

设置当前上下文的交换间隔

有两种处理未决事件的方法; 轮询和等待。

GLFWAPI void glfwPollEvents(void)

处理所有事件队列中的事件,事件处理会调用一些回调函数。一些平台下,窗口移动、resize和菜单 *** 作都会触发事件处理,block当前的任务。

GLFWAPI void glfwWaitEvents(void)

等待所有处理中和队列中的事件完成,当前线程会进入sleep状态,如果有事件可用,就相当与glfwPollEvents.

GLFWAPI void glfwTerminate(void)

这个函数终止GLFW,这个函数会注销调剩余的windows and cursors,复位所有修改过的gamma ramps,释放申请的资源。对应glfwInit

GLFWAPI void glfwInitHint(i

nt hint, int value)

设置制定的初始化hint值,这个设置之后中间不能进行修改直至结束。有些hints是平台相关,这些只有在对应的平台上才会生效。

GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)

查询GLFW库的版本,major, minor and revision号

GLFWAPI const char* glfwGetVersionString(void)

查询编译阶段的配置,返回的是个字符串,包含版本、平台、编译器和平台相关的编译阶段的选项

GLFWAPI int glfwGetError(const char** description)

查询错误码并清除上一次的错误信息

GLFWAPI GLFWmonitor** glfwGetMonitors(int* count)

查询当前的连接监视器connected monitors,返回的是当前所有连接的monitor,primary monitor永远是数组的第一个。

GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void)

查询primary monitor,task bar和global menu bar等基本信息都是显示在primary monitor中的。

GLFWAPI void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos)

获取虚拟屏幕中monitor的视口坐标

GLFWAPI void glfwGetMonitorWorkarea(GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height)

获取monitor的工作区,返回的是屏幕坐标的位置,左上角和size的值。工作区是屏幕中没有系统任务条的区域,如果系统没有任务条,就是全屏幕。

GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* widthMM, int* heightMM)

获取monitor的物理尺寸,单位是millimetres

GLFWAPI void glfwGetMonitorContentScale(GLFWmonitor* monitor, float* xscale, float* yscale)

获取monitor的content scale,这个值的计算:当前DPI与平台默认DPI之间的比。依赖于monitor的分辨率和设置的像素密度。

GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* monitor)

获取monitor的名称

GLFWAPI void glfwSetMonitorUserPointer(GLFWmonitor* monitor, void* pointer)

设置monitor中用户自定义的pointer

GLFWAPI void* glfwGetMonitorUserPointer(GLFWmonitor* monitor)

获取monitor的用户自定义pointer

GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count)

获取monitor的可用视频模式,返回的是一个数组,按照升序排列。

GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor)

获取monitor的当前的视频模式,如果是全屏模式,返回值以来窗口是否iconified

GLFWAPI void glfwSetGamma(GLFWmonitor* monitor, float gamma)

根据指定的exponent生成一个合适尺寸的gamma ramp(gamma斜度)并设置,参数必须是一个大于0的finite number,用于色彩矫正,理想值是1.

GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor)

获取当前的gamma ramp值

GLFWAPI void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp)

设置monitor的gamma ramp,第一次调用这个函数并存储gamma的值是在glfwTerminate函数中

GLFWAPI void glfwDefaultWindowHints(void)

reset窗口的所有hints值,全设置为默认的。

GLFWAPI void glfwDestroyWindow(GLFWwindow* window)

destory指定的window和context

GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value)

设置window的close flag。

GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title)

设置窗口的title

GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* images)

为窗口设置Icon,传入一组备选图像,会选择尺寸接近的作为图标,如果没有传图像,用默认的图标。图像是32bit小端non-premultiplied RGBA8,按行排列从左上角开始。图像的尺寸会根据平台和系统设置进行resize,一般包括16x16,32x32和48x48.

GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos)

获取指定区域的位置,返回的是屏幕坐标,原点在左上角

GLFWAPI void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos)

设置窗口坐标,如果是全屏没有效果

GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height)

获取窗口的size,以屏幕坐标为单位,不是framebuffer的尺寸。

GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight)

设置窗口的尺寸限制,如果是全屏模式,这个参数只有在创建窗口的时候其作用。其他情况下窗口要是可缩放的这个函数才有作用。

GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom)

设置窗口的aspect ratio,如果是全屏模式,这个参数只有在创建窗口的时候其作用。其他情况下窗口要是可缩放的这个函数才有作用。aspect ratios是长宽比要大于0。

GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height)

设置窗口的size.对于全屏窗口,此功能可更新其所需视频模式的分辨率并切换到最接近其的视频模式,而不会影响窗口的上下文。 由于上下文不受影响,因此帧缓冲区的位深度保持不变.

GLFWAPI void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height)

获取窗口的framebuffer的zise,以pixel为单位

GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom)

以屏幕坐标为单位检索指定窗口框架的每个边缘的大小。 包括标题栏。函数检索每个窗框边缘的大小,而不是沿特定坐标轴的偏移量,所以检索到的值将始终为零或正数。

GLFWAPI void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale)

此函数检索指定窗口的内容比例。 内容比例是当前DPI与平台默认DPI之比。 这对于文本和任何UI元素尤其重要。

GLFWAPI float glfwGetWindowOpacity(GLFWwindow* window)

获取窗苦的不透明度(alpha值),包括所有装饰物。该值时0到1之间的值,初始值为1.

GLFWAPI void glfwSetWindowOpacity(GLFWwindow* window, float opacity)

设置窗口的透明度

GLFWAPI void glfwIconifyWindow(GLFWwindow* window)

如果指定的窗口先前已还原,则此功能可图标化(最小化)指定的窗口。 如果窗口已被图标化,则此功能不执行任何 *** 作。 如果指定的窗口是全屏窗口,则将还原原始监视器分辨率,直到还原该窗口为止。

GLFWAPI void glfwRestoreWindow(GLFWwindow* window)

重置窗口,用在窗口进行了最大化或最小化的情况。如果指定的窗口是全屏窗口,则为该窗口选择的分辨率将在所选监视器上恢复。

GLFWAPI void glfwMaximizeWindow(GLFWwindow* window)

最大化窗口,如果窗口已经最大化,或是全屏模式不起作用

GLFWAPI void glfwShowWindow(GLFWwindow* window)

显示窗口,全屏不起作用,默认情况所有创建的窗口都是显示的,也可以通过glfwSetWindowAttrib设置GLFW_FOCUS_ON_SHOW_hint来设置

GLFWAPI void glfwHideWindow(GLFWwindow* window)

隐藏窗口,全屏不起作用

GLFWAPI void glfwFocusWindow(GLFWwindow* window)

此功能将指定的窗口置于最前面并设置输入焦点。 该窗口应该已经可见并且没有图标。 默认情况下,窗口和全屏模式窗口在最初创建时都会被聚焦。GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window)

该功能要求用户注意指定的窗口。 作用不详

GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window)

返回指定窗口处于全屏状态的监视器的句柄

GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate)

设置指定窗口处于全屏状态的监视器的句柄,这个函数会更新monitor的宽、高、视频模式的刷新率。

GLFWAPI int glfwGetWindowAttrib(GLFWwindow* window, int attrib)

获取窗口或GL/ES上下文相关的属性值,framebuffer相关的hints不是属性。

GLFWAPI void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value)

设置窗口的属性值,支持的属性包含:GLFW_DECORATED、GLFW_RESIZABLE、GLFW_FLOATING、GLFW_AUTO_ICONIFY、GLFW_FOCUS_ON_SHOW。

GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer)

设置window的user pointer

GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* window)

返回window的user pointer

GLFWAPI void glfwWaitEventsTimeout(double timeout)

等待超时。

GLFWAPI void glfwPostEmptyEvent(void)

向事件队列中插入一个空事件

GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode)

获取窗口输入选项的值,mode取值为:GLFW_CURSOR, GLFW_STICKY_KEYS, GLFW_STICKY_MOUSE_BUTTONS, GLFW_LOCK_KEY_MODS, GLFW_RAW_MOUSE_MOTION。

GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value)

设置窗口的输入模式,mode取值和get函数一样。

GLFWAPI int glfwRawMouseMotionSupported(void)

查询当前系统是否支持raw mouse motion,是否支持在初始化GLFW的时候一次确定,raw motion接近actual motion,它不受应用于桌面光标运动的缩放和加速度的影响。 该处理适合于光标,而原始运动更适合于控制3D相机。 因此,仅在禁用光标时才提供原始鼠标移动。

GLFWAPI const char* glfwGetKeyName(int key, int scancode)

获取按键名。

GLFWAPI int glfwGetKeyScancode(int key)

获取按键码。

GLFWAPI int glfwGetKey(GLFWwindow* window, int key)

获取按键的最后一个状态。

GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button)

获取鼠标的最后状态值。

GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos)

获取光标位置,屏幕坐标。

GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos)

设置光标位置,窗口必须有输入焦点,如果没有,这个函数无作用。原点在左上角。

GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)

创建一个自定义的光标,结合set一起使用,光比较的照片存储和图标的方式一样,按照像素,从左上角开始。

GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape)

以标准形状创建一个光标

GLFWAPI void glfwDestroyCursor(GLFWcursor* cursor)

销毁一个光标

GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor)

设置光标开始在窗口上进行使用,光标要显示害死哟啊设置光标的模式为GLFW_CURSOR_NORMAL。在一些平台上,如果已经有了输入焦点,这个光标就不会显示。

GLFWAPI int glfwJoystickPresent(int jid)

查询 *** 纵杆是否存在

GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)

返回 *** 纵杆所有轴的值,是一个数组,范围时-1到1

GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count)

返回 *** 纵杆的所有butto的状态,是一个数组,元素是按下或释放GLFW_PRESS or GLFW_RELEASE

GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count)

返回 *** 纵杆所有hats的状态,返回的也是一个数组

GLFWAPI const char* glfwGetJoystickName(int jid)

返回 *** 纵杆的名字,返回的是字符串

GLFWAPI const char* glfwGetJoystickGUID(int jid)

返回 *** 纵杆的SDL兼容GUID,是一个UTF-8的16进制编码

GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer)

*** 纵杆设置一个自动以指针值,

GLFWAPI void* glfwGetJoystickUserPointer(int jid)

返回用户自定义的 *** 纵杆指针值

GLFWAPI int glfwJoystickIsGamepad(int jid)

查询 *** 纵杆是否在gamepad上进行过map

GLFWAPI int glfwUpdateGamepadMappings(const char* string)

添加SDL_GameControllerDB gamepad映射。

GLFWAPI const char* glfwGetGamepadName(int jid)

获取 *** 纵杆游戏设备的名称

GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)

获取游戏pad中 *** 纵杆映射的状态,用在Xbox等游戏pad上。

GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string)

设置字符串的剪切板

GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window)

获取剪切板的内容,返回的时字符串。

GLFWAPI GLFWwindow* glfwGetCurrentContext(void)

返回当前县城的GL/ES上下文

GLFWAPI int glfwExtensionSupported(const char* extension)

查询指定的GL/ES扩展是否支持

GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)

赶回当前上下文支持的GL/ES函数地址,包含核心库和扩展库。

callback函数:

GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback)

设置 *** 纵杆配置的回调函数,也可以覆盖原来的回调函数,当 *** 纵杆连接或者断开连接的时候调用回调函数。回调函数的格式为:void function_name(int jid, int event)

GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun callback)

设置monitor的毁掉函数,如果之前又设置,会替换之前的值。

GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun callback)

设置window的position callback,当窗口移动的时候会调用这个回调函数,返回的位置是屏幕坐标的,左上角是原点

GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun callback)

设置窗口size的callback函数,当窗口resize的时候会调用,也是屏幕坐标。

GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun callback)

设置窗口关闭的callback,窗口关闭阿的时候调用。

GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun callback)

设置窗口刷新的callback函数,刷新窗口的时候调用,if the window has been exposed after having been covered by another window.

GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun callback)

设置窗口的focus回调函数,当窗口window gains or loses input focus时调用.

GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun callback)

设置iconification回调函数,窗口is iconified or restored时调用

GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback)

设置窗口最大化的回调函数,窗口最大化或复位时调用

GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun callback)

设置framebuffer resize的回调函数,当framebuffer resize时调用

GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback)

设置窗口的content scale回调函数,当窗口的content scale变化时调用

GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwiunning a test, x11perf determinendow* window, GLFWkeyfun callback)

设置按键的回调函数,在按键按下、重复和释放时调用回调函数。

GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun callback)

设置字符的回调函数,在输入指定字符编码时调用该回调函数。

GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun callback)

设置字符串编码修改的回调函数。

GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback)

设置鼠标按键的回调函数,鼠标按下或释放时触发,回调函数的格式:void function_name(GLFWwindow* window, int button, int action, int mods)

GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun callback)

设置光标位置回调函数,光标移动时触发。

GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun callback)

设置光标进入离开的回调函数,当光标进入或离开屏幕指定区域时触发。回调函数的格式为:void function_name(GLFWwindow* window, int entered)

GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun callback)

设置滚轮回调函数

回调函数void function_name(GLFWwindow* window, int path_count, const char* paths[])

GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun callback)

设置path drop回调函数,当一个或多份额dragged paths are dropped时触发。

vulkan函数:

GLFWAPI int glfwVulkanSupported(void)

查询是否找到Vulkan loader and any minimally functional ICD

GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count)

返回GLFW需要的Vulkan instance extensions,返回的个数组,里面包含了,创建vulkan surface时GLFW要的Vulkan实例扩展。

GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname)

返回specified Vulkan instance函数地址.

GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)

查询当前GLFW编译的指定物理设备的queue family是否显示图像

GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface)

创建一个surface。

①找到codeblocks安装目录下的MinGW文件夹(我的是这样子的:“E:\program

files\CodeBlocks\MinGW”)

这个目录下有include文件夹,打开它。在sdl包里面有一个include\SDL文件夹,把这个文件夹拖到你的电脑里面的include文件夹里。

②找到codeblocks安装目录下的MinGW文件夹(我的是这样子的:“E:\program

files\CodeBlocks\MinGW”)

这个目录下有lib文件夹,打开它。在sdl包里面有一个lib文件夹,把这个里面的三个文件“libSDL.dll.a,

libSDL.la和libSDLmain.a”拖到你电脑里的lib文件夹里面。

③把sdl包里面bin文件夹里面的SDL.dll文件拖到“C:\WINDOWS\system32”(我用的是XP系统)。当然,另外一个选择是将SDL.dll随时绑定到使用了SDL库编译的*.exe文件所在的文件夹中。这通常在发布你的程序的时候使用。

这样的话,基本的SDL就算是配置好了,可以用来写程序咯~!

用codeblocks新建一个空项目,在这个项目里面新建一个c++(我目前学的就是C++,java、C#什么的不感兴趣)文件。敲入下面的代码:

#include

<iostream>

#include

<SDL/SDL.h>

int

main(int

argc,

char*

argv[])

{

try

{

if(SDL_Init(SDL_INIT_EVERYTHING

==

-1))

throw"Could

not

initialize

SDL!"

}

catch(const

char*

s)

{

std::cerr<<s<<std::endl

return

-1

}

std::cout<<"SDL

initialized.\n"

SDL_Quit()

return

0

}

在左侧的Management窗口中,在项目上右击鼠标,选择构建选项,在横向目录里面选择“连接器设置”,添加“mingw32SDLmainSDL”(直接把双引号里面的内容复制进去就好),点击确定。发现添加了三行的连接库(这就对了),然后再此点击确定。

最后编译,运行。无误可以构建成功,虽然没有任何窗口生成,但是说明SDL配置和代码是没有问题的~!

在生成的debug文件夹下,生成了一个stdcout的txt文档。这个文档里面记录了程序的运行结果。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11507381.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存