动画=重绘+交换

glutPostRedisplay 标记当前窗口需要重新绘制。通过glutMainLoop下一次循环时,窗口显示将被回调以重新显示窗口的正常面板。多次调用glutPostRedisplay,在下一个显示回调只产生单一的重新显示回调。


在OpenGL中实现 双缓冲技术的一种简单方法:
1.在调用 glutInitDisplayMode函数时, 开启GLUT_DOUBLE,即 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);。这里将我们惯用的GLUT_SINGLE替换为GLUT_DOUBLE,意为要使用 双缓冲而非单缓冲。
2. 调用 glutDisplayFunc(display)注册 回调函数时, 在回调函数中所有绘制操作完成后调用glutSwapBuffers()交换两个缓冲区指针。
3. 调用 glutIdleFunc注册一个空闲时绘制操作函数, 注册的这个函数再调用display函数。
/*
 *  double.c
 *  This is a simple double buffered program.
 *  Pressing the left mouse button rotates the rectangle.
 *  Pressing the middle mouse button stops the rotation.
 */
#include <GL/glut.h>
#include <stdlib.h>

static GLfloat spin = 0.0;

void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   glPushMatrix();
   glRotatef(spin, 0.0, 0.0, 1.0);
   glColor3f(1.0, 1.0, 1.0);
   glRectf(-25.0, -25.0, 25.0, 25.0);
   glPopMatrix();
   glutSwapBuffers();
}

void spinDisplay(void)
{
   spin = spin + 2.0;
   if (spin > 360.0)
      spin = spin - 360.0;
   glutPostRedisplay();
}

void init(void) 
{
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_FLAT);
}

void reshape(int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

void mouse(int button, int state, int x, int y) 
{
   switch (button) {
      case GLUT_LEFT_BUTTON:
         if (state == GLUT_DOWN)
            glutIdleFunc(spinDisplay);
         break;
      case GLUT_MIDDLE_BUTTON:
      case GLUT_RIGHT_BUTTON:
         if (state == GLUT_DOWN)
            glutIdleFunc(NULL);
         break;
      default:
         break;
   }
}
   
/* 
 *  Request double buffer display mode.
 *  Register mouse input callback functions
 */
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
   glutInitWindowSize (250, 250); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
  
   glutReshapeFunc(reshape); 
   glutDisplayFunc(display); 
   glutMouseFunc(mouse); 
   glutMainLoop();
   return 0;   /* ANSI C requires main to return int. */
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/listinfo" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/round_style" android:elevation="4dp" android:layout_margin="8dp" android:clickable="true" android:padding="10dp"> <com.xuexiang.xui.widget.textview.autofit.AutoFitTextView android:id="@+id/code" style="@style/item_show_title" android:layout_width="14dp" android:layout_height="16dp" android:paddingTop="2dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <com.xuexiang.xui.widget.textview.autofit.AutoFitTextView style="@style/item_show_title" android:id="@+id/name" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/code"/> <com.xuexiang.xui.widget.textview.autofit.AutoFitTextView style="@style/item_show_title" android:id="@+id/spec" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/name"/> <com.xuexiang.xui.widget.textview.autofit.AutoFitTextView style="@style/item_show_title" android:id="@+id/composition" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/spec"/> <com.xuexiang.xui.widget.textview.autofit.AutoFitTextView style="@style/item_show_title" android:id="@+id/weight" app:layout_constraintStart_toEndOf="@+id/composition" app:layout_constraintTop_toBottomOf="@+id/spec"/> <ImageView android:id="@+id/status" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/name" app:layout_constraintTop_toTopOf="parent" /> <View style="@style/item_show" android:id="@+id/view_task_list" android:layout_width="match_parent" android:layout_height="1dp" android:background="#cccccc" android:layout_marginTop="3dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/composition" app:layout_constraintStart_toStartOf="@+id/composition"/> </androidx.constraintlayout.widget.ConstraintLayout>点击表格,显示弹窗展示列内容
06-04

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值