texture mapping issues

I have gotten my texture program working. Just one problem, when i run the program, it just displays the frame, with an empty window inside. Pretty sure the code is ok as i got it from another opengl expert, and it works on their computer. So why would it do this on mine? Any advice please, thanks

 
#include "stdafx.h"
#include "windows.h"
#include "gl/gl.h"
#include "glut.h"

#include <vector>
#include <string>
#include <fstream>

bool LoadBitmap(const std::string &filename, int texture) 
{
	std::ifstream file(filename.c_str(),std::ios::binary);

	if(!file)
	{
		return false;
	}

	BITMAPFILEHEADER fileheader; 
	BITMAPINFOHEADER infoheader;

	file.read(reinterpret_cast<char *>(&fileheader), sizeof(fileheader));
	file.read(reinterpret_cast<char *>(&infoheader), sizeof(infoheader));

	std::vector<byte> texturedata;
	unsigned amount = infoheader.biWidth * infoheader.biHeight;
	texturedata.reserve(amount * 4);

	for(unsigned i = 0; i < amount; i++)
	{            
		RGBTRIPLE rgb = {255,255,255};

		file.read(reinterpret_cast<char *>(&rgb), sizeof(rgb));
		texturedata.push_back(rgb.rgbtRed);
		texturedata.push_back(rgb.rgbtGreen);
		texturedata.push_back(rgb.rgbtBlue);
		texturedata.push_back(255);
	}

	glBindTexture(GL_TEXTURE_2D, texture);


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

	void *raw = &texturedata.front();
	glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, raw);
	gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, raw);

	return true;
}

GLuint texture = 0;

void draw()
{
	glClear(GL_COLOR_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,texture);


	glutSolidTeapot(0.5);
}

int win;

void keyboard(unsigned char key, int x, int y)
{
	if(key == 'q')
	{
		glutDestroyWindow(win);
		exit(0);
	}
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
	glutInitWindowSize(800,400);
	glutInitWindowPosition(100,100);
  
	win = glutCreateWindow("Hello");

	glutDisplayFunc(draw);
	glutKeyboardFunc(keyboard);

	glClearColor(0,0,0,0);

	glGenTextures(1, &texture);

	bool b = LoadBitmap("texture1.bmp",texture); 

	if(!b)
	{
		MessageBox(NULL,L"failed to load bitmap",L"Hello",MB_OK);
		return 1;
	}

	glutMainLoop();
}


In your code I don’t see you register a reshape function for glutReshapeFunc.
You need a function that is similar as this


void reshape(GLsizei width, GLsizei height)	
{
  glViewport(0,0,width,height);					
  glMatrixMode(GL_PROJECTION);					
  glLoadIdentity();							gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

  glMatrixMode(GL_MODELVIEW);			
  glLoadIdentity();					
}

And translate back you teapot a little bit.


glLoadIdentity();
glTranslatef(0.0,0.0,-z);
glutSolidTeapot(0.5);

i added that stuff in but for some reason i am getting the same error which is that only a frame is displayed with no window in the middle. Its hard to explain for this, but if you know java gui, its like a JFrame with no ContentPane. I presume the code is right, so is there somthing else which could cause this problem?

Just to be sure do you add a call for glutReshapeFunc(reshape) inside your main. Try to and a function void init(void) with glClearColor(1.0,0.0,0.0,1.0); inside to see if you will have a red background. call it just before glutMainLoop(). And by the way in the init function add glEnable(GL_DEPTH_TEST); and in your window creation add GLUT_DEPTH to have a depth buffer active.

Edit: And modify the call glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

Strange, i have added all that in and still exactly the same. I have tested all my other programs which are just basic drawing etc, and they all work fine. This is how the code is looking


#include "stdafx.h"
#include "windows.h"
#include "gl/gl.h"
#include "glut.h"

#include <vector>
#include <string>
#include <fstream>

bool LoadBitmap(const std::string &filename, int texture) 
{
	std::ifstream file(filename.c_str(),std::ios::binary);

	if(!file)
	{
		return false;
	}

	BITMAPFILEHEADER fileheader; 
	BITMAPINFOHEADER infoheader;

	file.read(reinterpret_cast<char *>(&fileheader), sizeof(fileheader));
	file.read(reinterpret_cast<char *>(&infoheader), sizeof(infoheader));

	std::vector<byte> texturedata;
	unsigned amount = infoheader.biWidth * infoheader.biHeight;
	texturedata.reserve(amount * 4);

	for(unsigned i = 0; i < amount; i++)
	{            
		RGBTRIPLE rgb = {255,255,255};

		file.read(reinterpret_cast<char *>(&rgb), sizeof(rgb));
		texturedata.push_back(rgb.rgbtRed);
		texturedata.push_back(rgb.rgbtGreen);
		texturedata.push_back(rgb.rgbtBlue);
		texturedata.push_back(255);
	}

	glBindTexture(GL_TEXTURE_2D, texture);


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

	void *raw = &texturedata.front();
	glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, raw);
	gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, raw);

	return true;
}

GLuint texture = 0;

void draw()
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,texture);


	glLoadIdentity();
	glTranslatef(0.0,0.0,-0.5);
	glutSolidTeapot(0.5);

}

void init(void)
{
glClearColor(1.0,0.0,0.0,1.0);
glEnable(GL_DEPTH_TEST);
}

void reshape(GLsizei width, GLsizei height)	
{
  glViewport(0,0,width,height);					
  glMatrixMode(GL_PROJECTION);					
  glLoadIdentity();							gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

  glMatrixMode(GL_MODELVIEW);			
  glLoadIdentity();					
}


int win;

void keyboard(unsigned char key, int x, int y)
{
	if(key == 'q')
	{
		glutDestroyWindow(win);
		exit(0);
	}
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH);
	glutInitWindowSize(800,400);
	glutInitWindowPosition(100,100);
  
	win = glutCreateWindow("Hello");
    
	glutDisplayFunc(draw);
	glutKeyboardFunc(keyboard);
    glutReshapeFunc(reshape);

	glClearColor(0,0,0,0);

	glGenTextures(1, &texture);

	bool b = LoadBitmap("texture1.bmp",texture); 

	if(!b)
	{
		MessageBox(NULL,L"failed to load bitmap",L"Hello",MB_OK);
		return 1;
	}
        init();
	glutMainLoop();

}


 

And i am just using a standard bmp image with the size 64*64. Does it work for you? Maybe there is somthing wrong with my software although i have only recently downloaded it. Very strange.

I will test it without texture because I am on Linux.

Ok, got it working without texture. I will try to add a texture over it with another library.

Edit: Got it working with a texture. Try first without a mipmap to see.

I have commented out everything which is to do with textures, and still the same problem. Very wierd. I am putting a window in my code arnt i? I am going to create a new project and see if it works and if not, i will try reinstalling it.
cheers