bmp image not loading - OpenGL

I am trying to load a bmp image in openGL using SOIL. The code below compiles but it does not display the image. It displays a plain white square. Any help will be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "SOIL.h"
#include    <windows.h>
#include    <stdio.h>
#include    <Gl\gl.h>
#include    <gl\gl.h>
#include    <gl\glu.h>
#include    <GL\glut.h>


bool* keyStates = new bool[256];
GLuint texture[1];

int GLTextures()
{
    texture[0] = SOIL_load_OGL_texture("lb.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
    if(texture[0] == 0) return false;
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    return true;
}
void reshape(int height, int width) {
    const float ar = (float) width / (float) height;
    glViewport(0, 10, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 90.0);
    gluLookAt(0, 2, 0, -1, 1, -3, 0, 1, 0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
}
void keyOperations (void) {
	if (!keyStates['a']) {}
}
static void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-5.0f);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
	glEnd();
	glutSwapBuffers();
}
void keyPressed (unsigned char key, int x, int y) {
	keyStates[key] = false;
}
void keyUp (unsigned char key, int x, int y) {
	keyStates[key] = true;
}
int main(int argc, char **argv)
{
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInit(&argc, argv);
    glutInitWindowSize(600, 600);
    glutCreateWindow("Project");
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
	glutKeyboardFunc(keyPressed);
	glutKeyboardUpFunc(keyUp);
	/////////////////////////////////////
	glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glutMainLoop();
}
Try removing lines 17, 18 and 19 - SOIL does that for you. Also, are you calling GLTextures at all? It should also return bool rather than int, and there is no need to include both variants of the GL/gl.h header. Apart from that, just try moving it around the scene to make sure that it is in view.
okay. I was trying to call it but I am not sure where I need to call GLTextures. Am I suppose to call it in the main? If so, what would the parameter be?
Yes, just call it in main, before you call glutMainLoop. It doesn't require parameters (you haven't declared it as taking any).
Thank you!!
Topic archived. No new replies allowed.