Linux之X11+OpenGL+EGL绘制(二十)

GLfloat

norm_x = 0.0,

norm_y = 0.0,

offset_x = 0.0,

offset_y = 0.0,

p1_pos_x = 0.0,

p1_pos_y = 0.0;

GLint phase_loc, offset_loc, position_loc;

bool update_pos = false;

const float vertexArray[] = {

0.0, 0.5, 0.0,

-0.5, 0.0, 0.0,

0.0, -0.5, 0.0,

0.5, 0.0, 0.0,

0.0, 0.5, 0.0

};

void render(){

static float phase = 0;

static int donesetup = 0;

static XWindowAttributes gwa;

draw

if ( !donesetup ) {

XWindowAttributes gwa;

XGetWindowAttributes ( x_display , win , &gwa );

glViewport ( 0 , 0 , gwa.width , gwa.height );

glClearColor ( 0.08 , 0.06 , 0.07 , 1.); // background color

donesetup = 1;

}

glClear ( GL_COLOR_BUFFER_BIT );

glUniform1f ( phase_loc , phase ); // write the value of phase to the shaders phase

phase = fmodf ( phase + 0.5f , 2.f * 3.141f ); // and update the local variable

if ( update_pos ) { // if the position of the texture has changed due to user action

GLfloat old_offset_x = offset_x;

GLfloat old_offset_y = offset_y;

offset_x = norm_x - p1_pos_x;

offset_y = norm_y - p1_pos_y;

p1_pos_x = norm_x;

p1_pos_y = norm_y;

offset_x += old_offset_x;

offset_y += old_offset_y;

update_pos = false;

}

glUniform4f ( offset_loc , offset_x , offset_y , 0.0 , 0.0 );

glVertexAttribPointer ( position_loc, 3, GL_FLOAT, false, 0, vertexArray );

glEnableVertexAttribArray ( position_loc );

glDrawArrays ( GL_TRIANGLE_STRIP, 0, 5 );

eglSwapBuffers ( egl_display, egl_surface ); // get the rendered buffer to the screen

}

int main(){

/// the X11 part //

// in the first part the program opens a connection to the X11 window manager

//

x_display = XOpenDisplay ( NULL ); // open the standard display (the primary screen)

if ( x_display == NULL ) {

cerr << “cannot connect to X serve

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值