2013-09-26 4 views
0

텍스처를 사용하여 이미지를 OpenGL에 삽입하려고합니다. 우분투 리눅스를 사용하고 있습니다. 이것은 내 주요 코드 :gluBuild2DMipmap에서 OpenGL에 이미지를 삽입하는 중 오류가 발생했습니다.

#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}’ 

답변

1

num2.c 파일은 여러 멤버가있는 구조체로 gimp_image을 선언하지만 display 함수에서는 GLuint 유형의 gimp_image을 만듭니다. 이 로컬 변수는 글로벌 변수를 음영 처리하므로 gimp_image.bytes_per_pixel에 액세스 할 때 전역 변수가 아닌 로컬 변수 (정수)를 찾습니다. 정수에는 멤버가 없으므로 오류가 발생합니다.

+0

Gluint gimp_image를 이미지로 변경 한 후 문제가 해결되었습니다. 고맙습니다. – meteors

관련 문제