gpt4 book ai didi

c++ - 'glPopMatrix':找不到标识符

转载 作者:行者123 更新时间:2023-12-02 10:17:42 43 4
gpt4 key购买 nike

我正在OpenGL项目上工作,即使我包含glut.h并链接了诸如opengl32.lib,glfw3.lib,glaux.lib,glu32.lib,glut32.lib之类的常见库文件,也遇到了以下编译错误。以下是我的代码片段无法正常运行(cpu_fan.h):

#ifndef CPU_FAN
#define CPU_FAN
#include "parameter.h"
#include "dragHandler.h"
#include <iostream>
#include <glad/glad.h>
#include <GLFW\glfw3.h>
#include "motion.h"
#include "objects.h"
#include "bitmap.h"
#include "light.h"
#include <GL/glut.h>
#include <windows.h>

class cpu_fan {
private:GLfloat c_center[3] = { 0.0075, 0.0075, 0.0075};
GLfloat c_meshCylinder[3] = { 0.0075, 0.0075, 0.0075 };
GLfloat c_meshBlade[3] = { 0.015, 0.015, 0.015 };
GLfloat c_rim[3] = { 0., 0., 0. };
GLfloat c_blade[3] = { .0 , .0, .0 };
GLfloat fan_spin_theta = 0, y_spin = 0;
GLuint fan_no_blades = 6;
int sides = 30;
float rim_start = 0., rim_end = -0.9;
float mesh_start = rim_end - 0.05, mesh_end = mesh_start - 3.;
int meshCount = 50;
GLfloat v_blade[30][3] = { {0.5, 0., -0.6},
{4.05, 0.9, 0.},
{4.9, 2., 0.},
{5.5, 3., 0.},
{6.15, 4., 0.},
{6.73, 5., 0.},
{7.23, 6., 0.},
{7.55, 7., 0.},
{8.1, 8., 0.},
{8.5, 9., 0.},
{8.8, 10., 0.},
{9.1, 11., 0.},
{9.28, 12., -0.1},
{9.47, 13., -0.15},
{9.51, 14., -0.2},
{9.4, 15., -0.25},
{9., 15.8, -0.3},
{8., 16.72, -0.35},
{7., 17.3, -0.4},
{6., 17.60, -0.45},
{5., 17.70, -0.5},
{4., 17.57, -0.55},
{3., 17.4, -0.6},
{2., 16.46, -0.65},
{1.3, 16., -0.7},
{1., 15.46, -0.75},
{0.5, 15., -0.8},
{0.15, 14., -0.85},
{0.123, 13., -0.9},
{0.12, 12., -0.95} };
point3D move;
GLfloat viewTheta = 0.;

bool visible = true;
bool objMove = false;

void draw_fan_blades();
void draw_fan_center();
void draw_fan_rim();
void draw_cooler_grills();
void showDescrpiton();
void motionHandle();
public: void render();
};

void cpu_fan::showDescrpiton() {
GLfloat diff = 1.5;

glPushMatrix();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

// Transperent Glass Frame
glColor4f(0., 0., 0., .7);
glBegin(GL_POLYGON);
glVertex3f(-10., -10., objLoc.z - diff);
glVertex3f(-10., 10., objLoc.z - diff);
glVertex3f(10., 10., objLoc.z - diff);
glVertex3f(10., -10., objLoc.z - diff);
glEnd();
glPopMatrix();
}

void cpu_fan::motionHandle() {

if (((enterPressed && objIndex == REMOVE_FAN) || objMove == true) && !assemble)
{
objMove = true;
move.x -= 0.007;
if (move.x < disapphereLimit)
{
enterPressed = false;
visible = false;
objMove = false;
}
}
else if (((enterPressed && objIndex == REMOVE_FAN-1) || objMove == true) && assemble)
{
objMove = true;
visible = true;
move.x += 0.007;
if (move.x >= 0.)
{
enterPressed = false;
objMove = false;
}
}
}

void cpu_fan::render() {
motionHandle();
if (!visible) return;
glPushMatrix();
glTranslatef(move.x, move.y, move.z);
glRotatef(viewTheta, 0., 1., 0.);
glColor3f(.001, 0.001, .001);
glTranslatef(-0.974, .52, -0.745);
glTranslatef(8.72, 4.321, -3.821);
/// Remove this to stop rotate
//glRotatef(y_spin * 0.5, 0., 1., 0.); //Rotate whole on Y axis
//y_spin += 2.;
//if (y_spin >= 720.) y_spin = 0;
glRotatef(-90., 0., 1., 0.);
glScalef(0.009375, 0.009375, 0.046875);
draw_fan_blades();
draw_fan_center();
draw_fan_rim();
draw_cooler_grills();
glPopMatrix();
}

我的main.cpp的片段:
#include <iostream>
#include <glad/glad.h>
#include <GLFW\glfw3.h>
#include "parameter.h"
#include "motion.h"
#include "objects.h"
#include "bitmap.h"
#include "light.h"
#include <GL/glut.h>
#include <windows.h>

/* TEXTURE HANDLING */
void loadTexture(GLuint texture, const char* filename) {
BmpLoader image(filename);
glBindTexture(GL_TEXTURE_2D, texture);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image.iWidth, image.iHeight, GL_RGB, GL_UNSIGNED_BYTE, image.data);
}

void textureInit() {
// Create Texture.
textures = new GLuint[NUM_TEXTURE];
glGenTextures(NUM_TEXTURE, textures);

// Load the Texture.
for (int i = 0; i < NUM_TEXTURE; i++)
loadTexture(textures[i], texPath[i]);
}

/* REDNDERING HANDLING */
void change_size(int w, int h) {
// Update global parameters
width = w;
hight = h;
// Do reshape
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float ratio = 0.0f;
h = h == 0 ? 1 : h;
ratio = (float)w / (float)h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80.0f, ratio, 0.7f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}

我在Visual Studio 2019中遇到的生成错误:
1>------ Build started: Project: desktop-simulator, Configuration: Debug Win32 ------
1>main.cpp
1>C:\Users\username\cpu_fan.h(7,56): warning C4305: 'initializing': truncation from 'double' to 'GLfloat'
1>C:\Users\username\cpu_fan.h(8,57): warning C4305: 'initializing': truncation from 'double' to 'GLfloat'
1>C:\Users\username\cpu_fan.h(9,51): warning C4305: 'initializing': truncation from 'double' to 'GLfloat'
1>C:\Users\username\cpu_fan.h(15,39): warning C4305: 'initializing': truncation from 'double' to 'float'
1>C:\Users\username\cpu_fan.h(16,30): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
1>C:\Users\username\cpu_fan.h(16,60): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
1>C:\Users\username\cpu_fan.h(47,28): warning C4305: 'initializing': truncation from 'double' to 'GLfloat'
1>C:\Users\username\cpu_fan.h(66,2): error C3861: 'glPushMatrix': identifier not found
1>C:\Users\username\cpu_fan.h(71,2): error C3861: 'glColor4f': identifier not found
1>C:\Users\username\cpu_fan.h(72,10): error C2065: 'GL_POLYGON': undeclared identifier
1>C:\Users\username\cpu_fan.h(72,2): error C3861: 'glBegin': identifier not found
1>C:\Users\username\cpu_fan.h(73,3): error C3861: 'glVertex3f': identifier not found
1>C:\Users\username\cpu_fan.h(74,3): error C3861: 'glVertex3f': identifier not found
1>C:\Users\username\cpu_fan.h(75,3): error C3861: 'glVertex3f': identifier not found
1>C:\Users\username\cpu_fan.h(76,3): error C3861: 'glVertex3f': identifier not found
1>C:\Users\username\cpu_fan.h(77,2): error C3861: 'glEnd': identifier not found
1>C:\Users\username\cpu_fan.h(78,2): error C3861: 'glPopMatrix': identifier not found
1>C:\Users\username\cpu_fan.h(110,2): error C3861: 'glPushMatrix': identifier not found

请帮助我解决这个问题

提前致谢

最佳答案

不推荐使用glPushMatrixglPopMatrix等(Legacy OpenGL),并且在核心配置文件OpenGL context中不可用。您必须使用兼容性配置文件OpenGL上下文,并且必须生成相应的OpenGL加载程序。
Glad加载器生成器提供“配置文件”选项,可以将其设置为“兼容性”或“核心”

关于c++ - 'glPopMatrix':找不到标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61403128/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com