C : 过多不刷新窗口,为什么?

问题描述 投票:0回答:1

我试图显示一个只有两个面的简单三角形,但是当我执行它时,尝试旋转三角形,只是没有刷新:((仅当我全屏显示,或最小化并重新最大化它时刷新)

我的代码:

#include <GL/freeglut.h>
#include <GL/gl.h>
#include <stdio.h>
#include <math.h>//useless but I will need it soon.

float rotx, roty = 0.0f;

char srotx[40];

int win;

void display()
{
    
    glViewport(0,0,1000,800);
    
    glBegin(GL_QUADS);
    glColor3f(0.5,0,0);
    glVertex3f(0.5,0.5,0);
    glColor3f(0,0.5,0);
    glVertex3f(-0.5,0.5,0.5);
    glColor3f(0,0,0.5);
    glVertex3f(0,-0.5,0.5);
    glColor3f(0.5,0.5,0);
    glVertex3f(-0.5,0.5,-0.5);
    glEnd();
    
    glRotatef(rotx,1.0f,0.0f,0.0f);
    glRotatef(roty,0.0f,1.0f,0.0f);
    
    glutSetWindowTitle(srotx);//not working
    glutSwapBuffers();
    
}

void BindInput(unsigned char key, int Mx, int My)
{
    switch(key)
    {
        case 'z' :
            rotx += 0.2f;
            break;
        case 's' :
            rotx -= 0.2f;
            break;
        case 'd' :
            roty += 0.2f;
            break;
        case 'q' :
            roty -= 0.2f;
            break;
    }

    if(key == 27)
    {
        glFinish();
        exit(0);
    }
    if(rotx >= 360.0f || key == 'a' || roty >= 360.0f)
    {
        glutPostWindowRedisplay(win);//testing...
        rotx = 0.0f;
        roty = 0.0f;
    }
    glutPostRedisplay();
}

int main(int argc, char* argv[])
{
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(1000,800);
  
  sprintf(srotx, "DEBUG Mayo Test, rotx : %f", rotx);
  win = glutCreateWindow(srotx);
  glutSetCursor(GLUT_CURSOR_DESTROY);
  glEnable(GL_DEPTH_TEST);
  glMatrixMode(GL_PROJECTION);
  glutDisplayFunc(display);
  glutIdleFunc(display);
  glutKeyboardFunc(BindInput);
  glutMainLoop();

  return 0;
 
}

截图: Starting spining it, no refresh

还有tasks.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc générer le fichier actif",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-lglut",
                "-lGLU",
                "-lGL"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Tâche générée par le débogueur."
        },
    ],
    "version": "2.0.0"
}

我尝试在互联网上搜索,但我发现的所有东西都不起作用。

在 Visual Studio 代码上使用 Xubuntu 22.04 (X11)。 预先感谢您的回复。

c freeglut
1个回答
0
投票
import React from 'react'
import { useEffect } from 'react';
import { useState } from 'react'
import axios from 'axios';

function Todo() {

    const [todos,settodos]=useState([]);
    const [todoid, settodoid]=useState('');
    const apiurl ='https://jsonplaceholder.typicode.com/todos';

    useEffect(()=>{
      fetchtodos();
    },[]);

    const fetchtodos=()=>{
     axios.get(apiurl).then((res)=>{
      settodos(res.data);
     });
    }


    const getTodo=()=>{
      axios.get(`${apiurl}/${todoid}`)
      .then((res)=>{
        settodos([...todos,res.data]);
      })
    }

    const todocompleted=(id)=>{
      const updated=todos.filter(todo=> todo.id !==id);
      settodos(updated);

    }



  return (
    <>
    <input type="text" placeholder='enter todo id' value={todoid} onChange={(e)=>settodoid(e.target.value)} />
    <button onClick={getTodo}>fetch data</button>
    <div> 
      <ul>
      {todos.map((todo)=>(
        <li>
          <label>
            <input type="checkbox" checked={todo.completed}  onChange={()=>todocompleted(todo.id)}/>
            {todo.title}
          </label>
        </li>
        ))}
      </ul>
    </div>
    </>
  )
}

export default Todo
© www.soinside.com 2019 - 2024. All rights reserved.