简体   繁体   English

土壤质地

[英]opengl Soil texture

Here is the error message I am recieving from VS2010: 这是我从VS2010收到的错误消息:

Unhandled exception at 0x77358dc9 in AzimuthalEqui.exe: 0xC0000005: Access violation writing location 0x00000014. AzimuthalEqui.e​​xe中0x77358dc9处未处理的异常:0xC0000005:访问冲突写入位置0x00000014。

The line of code generating this error is: 产生此错误的代码行是:

texture[1] = SOIL_load_OGL_texture
    (
        texture_filename,
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID, // create ID automatically
        SOIL_flags
    );

before entering this function: 进入此功能之前:

texture_filename = "Data/texture.jpg" texture_filename =“数据/纹理.jpg”

SOIL_LOAD_AUTO (= 0) SOIL_LOAD_AUTO(= 0)

SOIL_CREATE_NEW_ID (=0) SOIL_CREATE_NEW_ID(= 0)

SOIL_flags = 16 (=SOIL_FLAG_INVERT_Y) SOIL_flags = 16(= SOIL_FLAG_INVERT_Y)

The problem is that when I include a file I have written to parse some information in a text file an error is generated, otherwise the texture loads and is displayed. 问题是,当我包含一个为解析文本文件中的某些信息而编写的文件时,将生成错误,否则将加载纹理并显示该纹理。 The prob is most likely caused by one function as when this particular function is removed the code loads and displays the texture. 该概率最有可能是由一个函数引起的,因为当删除此特定函数时,代码将加载并显示纹理。 Here is the function that when added to my project makes the error occur: 这是添加到我的项目中会导致错误发生的函数:

[CODE]
void get_user_points(double *lats, double *longs){

    char buffer[BUFFSIZE_PARSE];
    char *p_buff = buffer;
    FILE *fp;
    const char *filename = "Points.txt";
    double temp;
    double *tmp_p = &temp;


    fp = fopen(filename,"r+");
    if (fp == NULL)
    {
        sprintf(buffer, "Can't Find File: %s", filename);
        MessageBoxA(NULL, buffer, "ERROR", MB_OK|MB_ICONEXCLAMATION);
        exit(0);
    }

    fgets(buffer, BUFFSIZE_PARSE, fp);

    while (*(p_buff+1) != '\0'){

        p_buff = get_next_letter(p_buff);

        switch (tolower(*p_buff)){
            case 'n':
                putchar(*p_buff);
                p_buff++;
                p_buff=get_next_double(lats, p_buff);
                printf(" = %f\n", *lats);
                break;
            case 's':
                ...
                ...
        }
    }
    putchar('\n');
    fclose(fp);
}

It has something to do with opening the file for reading... if I comment out these lines the texture loads correctly: 它与打开文件进行读取有关...如果我注释掉这些行,纹理将正确加载:

//fpr = fopen(filename2,"rb"); 
...
...
...
//fclose(fpr);

Here is my reduced code (i don't think this is the issue but just in case). 这是我简化的代码(我不认为这是问题,但以防万一)。 [There may be some remanants of my full code]: [我的完整代码可能还有些剩余]:

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    {
        printf("Initialising...\n");
        glutInitWindowSize(700, 700);
        glutInitWindowPosition(0, 0);
        glutCreateWindow ("SOIL Texture Test");
    }

    InitGL();
    glutDisplayFunc(DrawGLScene);
    glutReshapeFunc(ReSizeGLScene);

    glutMainLoop();

    return 0;
}

int InitGL(GLvoid) // Setup OpenGL
{
    //Load textures
    if (!LoadGLTextures())                              // Jump To Texture Loading Routine ( NEW )
    {
        MessageBox(NULL,TEXT("Cannot Load Image for Texture Map"),TEXT("Error!"),MB_OK | MB_ICONINFORMATION);
        //return false;                                 // If Texture Didn't Load Return FALSE ( NEW )
    }
    else
        glEnable(GL_TEXTURE_2D);                        // Enable texture mapping


    glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);               // Set the background colour (to black)

    glClearDepth(1.0f);                                 // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
    glDepthFunc(GL_LEQUAL);                             // Select testing type


    //get_user_points(&user_lat[0], &user_long[0]);

    return true;                                        // Initialization went OK
}


void DrawGLScene(GLvoid) // OpenGL drawing function
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the Screen and the Depth Buffer

    glLoadIdentity();
    glTranslatef(0.0f,0.0f,z);

    glBindTexture (GL_TEXTURE_2D, texture[filter]);
    glBegin (GL_QUADS);
        glNormal3f(0, 0, 1);

        glTexCoord2f (0,0);
        glVertex3f (-3,-3 ,0);
        glTexCoord2f (1,0 );
        glVertex3f (3,-3 , 0);
        glTexCoord2f (1, 1);
        glVertex3f (3,3 , 0);
        glTexCoord2f (0,1 );
        glVertex3f (-3,3 ,0 );
    glEnd();

    glFlush();
}

void ReSizeGLScene(int w, int h) // Code to resize (and initialise) the OpenGL scene (run once when in fullscreen mode)
{
    // Set up perspective view matrix
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, (GLfloat)w/(GLfloat)h, 0.1f, 100.0f);
    //glOrtho(-50.0, 50.0, -50.0, 50.0, -50.0, 50.0);

    // Set up modelview matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

int LoadGLTextures(void) // Load Bitmaps And Convert To Textures
{
    unsigned int SOIL_flags;
    GLint mag_param;
    GLint min_param;

    printf("Loading Textures... ");

    SOIL_flags = SOIL_FLAG_INVERT_Y;
    mag_param = GL_NEAREST;
    min_param = GL_NEAREST;


    texture[1] = SOIL_load_OGL_texture
    (
        texture_filename,
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID, // create ID automatically
        SOIL_flags
    );

    if(texture[1] == 0)
        return false;

    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag_param);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min_param);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    printf("Textures Loaded\n");
    return true;
}

在项目中包含.c文件而不是.lib文件可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM