gpt4 book ai didi

c++ - 在 gluBuild2DMipmaps 中将图像插入 openGL 时出错

转载 作者:行者123 更新时间:2023-11-28 07:24:07 25 4
gpt4 key购买 nike

我正在尝试使用纹理在 openGL 中插入图像。我正在使用 Ubuntu Linux。这是我的主要代码:

#include <iostream>
#include <GL/gl.h>
#include <GL/glut.h>
#include <math.h>
#include "Images/num2.c"

using namespace std;

void display() {
glClear (GL_COLOR_BUFFER_BIT);
/* create the image variable */
GLuint gimp_image;

/* assign it a reference. You can use any number */
glGenTextures(1, &gimp_image);

/* load the image into memory. Replace gimp_image with whatever the array is called in the .c file */
gluBuild2DMipmaps(GL_TEXTURE_2D, gimp_image.bytes_per_pixel, gimp_image.width, gimp_image.height, GL_RGBA, GL_UNSIGNED_BYTE, gimp_image.pixel_data);

/* enable texturing. If you don't do this, you won't get any image displayed */
glEnable(GL_TEXTURE_2D);

/* draw the texture to the screen, on a white box from (0,0) to (1, 1). Other shapes may be used. */
glColor3f(1.0, 1.0, 1.0);

/* you need to put a glTexCoord and glVertex call , one after the other, for each point */
glBegin(GL_QUADS);
glTexCoord2d(0.0, 1.0); glVertex2d(0.0, 0.0);
glTexCoord2d(0.0, 0.0); glVertex2d(0.0, 1.0);
glTexCoord2d(1.0, 0.0); glVertex2d(1.0, 1.0);
glTexCoord2d(1.0, 1.0); glVertex2d(1.0, 0.0);
glEnd();

/* clean up */
glDisable(GL_TEXTURE_2D);
glDeleteTextures(1, &gimp_image);
glFlush();
}


void init (void) {
/* select clearing (background) color */
glClearColor (1.0, 1.0, 1.0, 0.0);

/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (400, 300);
glutCreateWindow ("MineSweeper");
init ();

glutDisplayFunc(display);
glutMainLoop();
return 0;
}

我使用的 num2.c 文件的代码是 here

在使用以下选项编译时:g++ temp.cpp -lGL -lGLU -lglut 我收到以下错误:

temp.cpp:23:46: error: request for member ‘bytes_per_pixel’ in ‘gimp_image’, which is   of non-class type ‘GLuint {aka unsigned int}’
temp.cpp:23:74: error: request for member ‘width’ in ‘gimp_image’, which is of non-class type ‘GLuint {aka unsigned int}’
temp.cpp:23:92: error: request for member ‘height’ in ‘gimp_image’, which is of non-class type ‘GLuint {aka unsigned int}’
temp.cpp:23:138: error: request for member ‘pixel_data’ in ‘gimp_image’, which is of non-class type ‘GLuint {aka unsigned int}’

最佳答案

您的 num2.c 文件将 gimp_image 声明为具有多个成员的结构,但是在您的 display 函数中,您创建了一个 GLuint 类型的 gimp_image。这个局部变量会影响全局变量,因此当您尝试访问 gimp_image.bytes_per_pixel 时,它会查找局部变量(整数)而不是全局变量。由于整数没有成员,因此它会给您一个错误。

关于c++ - 在 gluBuild2DMipmaps 中将图像插入 openGL 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018615/

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