I am trying to dispaly a draped aerial image as a texture in 2D, but am encountering the following when loading the texture call:
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_INT, Image);
// Experiencing Unhandled exception at 0x77d615de in DrawVtxs081912.exe:
// 0xC0000005: Access violation reading location 0x0f0cfffc.
I appear to be successfully creating a window and reading the RGBA file with the following charactersistics:
Subfile Type Zero
ImageWidth 5529
ImageHeight 7079
BitsPerSample 8,8,8
Compression Uncompressed
Photmetric RGB
TopLeft Orientation
Here is the ocde I am using:
// DrawVtxs081912.cpp : Defines the entry point for the application.
//
#include “stdafx.h”
#include “DrawVtxs081912.h”
#include “tiffio.h”
#include “tiffiop.h”
#define MAX_LOADSTRING 100
#pragma comment(lib,“opengl32.lib”)
//#pragma comment(lib, “libtiff”)
#pragma comment(lib, “libtiff.lib”)
void EnableOpenGL(HWND hWnd, HDC*, HGLRC*);
void DisableOpenGL(HWND hWnd, HDC, HGLRC);
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
// Global Variables:
HDC hDC;
HGLRC hRC;
HWND hWnd;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
BOOL Done = FALSE;
MSG msg;
HACCEL hAccelTable;
//float theta = 0.0f;
TIFF *fpTIFFImage;
unsigned int height;
unsigned int width;
// Modulo sizes for the image height and width
unsigned int imageHeight;
unsigned int imageWidth;
//unsigned int BitsPerSample;
unsigned int *Image;
unsigned int *stopOnError= 0;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DRAWVTXS081912, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DRAWVTXS081912));
// Load the TIFF Image to be used as a texture
if(fpTIFFImage = TIFFOpen("C:\\Users\\Steve\\Gettysburg020512\\39077g25.tif", "r"))
{
TIFFGetField(fpTIFFImage, TIFFTAG_IMAGELENGTH, &height);
TIFFGetField(fpTIFFImage, TIFFTAG_IMAGEWIDTH, &width);
//TIFFGetField(fpTIFFImage, TIFFTAG_BITSPERSAMPLE, &BitsPerSample);
Image = (unsigned int *)_TIFFmalloc(height*width*sizeof(unsigned int));
TIFFReadRGBAImage(fpTIFFImage, width, height, Image, 0);
// Make the image a texture for display and reuse in subsequent displays
glBindTexture(GL_TEXTURE_2D, 1);
// RGB aligned in byte order one byte each
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Voodoo magic here
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// No lighting effects here - just the color
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
//glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
//glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_INT, Image);
// The texture width and height must be modulo of a power of 2
imageWidth = 2;
while (imageWidth < width)
{
imageWidth = imageWidth * 2;
}
imageHeight = 2;
while (imageHeight < height)
{
imageHeight = imageHeight * 2;
}
//glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_INT, Image);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_INT, Image);
// Experiencing Unhandled exception at 0x77d615de in DrawVtxs081912.exe:
// 0xC0000005: Access violation reading location 0x0f0cfffc.
};
// Prime the message flow
PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE);
// Main message loop:
//while (PeekMessage(&msg, hWnd, WM_KEYFIRST|WM_MOUSEFIRST,WM_KEYLAST|WM_MOUSELAST, PM_REMOVE))
//while (GetMessage(&msg, NULL, 0, 0) != -1)
while (msg.message != WM_QUIT)
{
if(PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
hDC = GetDC(msg.hwnd);
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
// OpenGL animation code goes here
//glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
//glClear( GL_COLOR_BUFFER_BIT );
//glPushMatrix();
//glRotatef( theta, 0.0f, 0.0f, 1.0f );
//glBegin( GL_TRIANGLES );
//glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
//glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
//glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
//glPointSize(10.0f);
// Make the image a texture for display and reuse in subsequent displays
//Is this seocnd call to glBindTexure needed inside the loop?
glBindTexture(GL_TEXTURE_2D, 1);
glEnable (GL_TEXTURE_2D);
glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3f (0.0, 7078.0, 0.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (5528.0, 7078.0, 0.0);
glTexCoord2f (1.0, 1.0);
glVertex3f (5528.0, 0.0, 0.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0.0, 0.0, 0.0);
glEnd ();
/***
glBegin( GL_POINTS );
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(0.0f, 1.0);
glColor3f(0.5f, 0.5f, 0.5f); glVertex2f(0.5f, 0.5f);
glEnd();
glPopMatrix();
**/
SwapBuffers( hDC );
// theta += 1.0f;
}
}
}
DisableOpenGL(hWnd, hDC, hRC);
DestroyWindow(hWnd);
return (int) msg.wParam;
}
Any suggestions would be appreciated.
Steve