首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ImGUI时不绘制形状的过剩

使用ImGUI时不绘制形状的过剩
EN

Stack Overflow用户
提问于 2022-03-08 16:39:57
回答 1查看 400关注 0票数 1

我在使用Windows 10,visual 2022。后端: imgui_impl_glut.cpp和imgui_impl_opengl3.cpp

现在,我只是想让freeGLUT和ImGUI一起正常工作。问题是,当我用ImGUI创建一个窗口时,它没有显示过剩绘制的形状。如果没有ImGUI,它就能很好地绘制一个球体。

在ImGui呈现周期之后,我尝试过为球体调用我的呈现过程,但这没有起作用。这是我的代码:

代码语言:javascript
复制
#include <iostream>
#include <GLEW/glew.h>
#include <GL/freeglut.h>
#pragma comment(lib, "glew32.lib")


#include "imgui/imgui.h"
#include "imgui/imgui_impl_glut.h"
#include "imgui/imgui_impl_opengl3.h"

#ifdef _MSC_VER
#pragma warning (disable: 4505) // unreferenced local function has been removed
#endif

static bool show_demo_window = true;
static bool show_another_window = false;
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);

   
void Window(int w, int h) {
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 200.0);
    glMatrixMode(GL_MODELVIEW);
}



void my_display_code()
{


    // Sample code taken from the ImGUI example files
    {
        static float f = 0.0f;
        static int counter = 0;

        ImGui::Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.

        ImGui::Text("This is some useful text.");               // Display some text (you can use a format strings too)
        ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our window open/close state
        ImGui::Checkbox("Another Window", &show_another_window);

        ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f
        ImGui::ColorEdit3("clear colour", (float*)&clear_color); // Edit 3 floats representing a color

        if (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)
            counter++;
        ImGui::SameLine();
        ImGui::Text("counter = %d", counter);

        ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
        ImGui::End();
    }

    // Other sample window
    if (show_another_window)
    {
        ImGui::Begin("Another Window", &show_another_window);   // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
        ImGui::Text("Hello from another window!");
        if (ImGui::Button("Close Me"))
            show_another_window = false;
        ImGui::End();
    }
}




//Function where the rendering occurs
void Draw(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();


    my_display_code();

    //Rendering
    ImGui::Render();
    ImGuiIO& io = ImGui::GetIO();

    glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);

    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());


    gluLookAt(5.0f, 35.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    OrbitPath();

    GLUquadric* quadric;
    quadric = gluNewQuadric();

    //Drwaing the Sun
    glPushMatrix();
    glRotatef(0.0, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0f, 0.0);
    glPushMatrix();
    glRotatef(0, 1.0, 0.0, 0.0);
    glRotatef(10, 0.0, 1.0, 0.0);
    glColor3f(1.0f, 1.0f, 1.0f);
    gluQuadricTexture(quadric, 1);
    gluSphere(quadric, 5, 10.0, 10.0);
    glPopMatrix();
    glPopMatrix();

    glutPostRedisplay();
    glutSwapBuffers();
}


//Main function
int main(int argc, char** argv) {
    glutInit(&argc, argv);

    glutInitContextVersion(4, 2);
    glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(700, 700);
    glutInitWindowPosition(500, 0);
    glutCreateWindow("Example");
    glutDisplayFunc(Draw);
    glutReshapeFunc(Window);

/**/
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO(); (void)io;

    ImGui::StyleColorsDark();



    ImGui_ImplGLUT_Init();
    ImGui_ImplGLUT_InstallFuncs();
    ImGui_ImplOpenGL3_Init();
/**/

    glewExperimental = GL_TRUE;
    glewInit();

    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);
    glutMainLoop();

    ImGui_ImplOpenGL3_Shutdown();
    ImGui_ImplGLUT_Shutdown();
    ImGui::DestroyContext();
}

使用ImGUI 1.87。

EN

回答 1

Stack Overflow用户

发布于 2022-03-08 16:45:04

您正在混合和匹配(或者更确切地说,不是匹配) imgui正在使用的现代模块化管道(注意OpenGL3头)和过时的固定管道过剩(以及您自己)正在使用。

简单地说,不要使用过剩,而是使用现代管道。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71398505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档