Re: opengl program to load a bmp runtime error (using freeglut 2.4)



On Feb 4, 12:18 am, fungus <openglMYSO...@xxxxxxxxxx> wrote:
On Feb 3, 12:37 pm, ashjas <ash...@xxxxxxxxx> wrote:



the program compiles fine...
but when i do ./a.out the following error appears and no window
loads..

freeglut (./a.out): ERROR: Internal error <Visual with necessary
capabilities not found> in function fgOpenWindow

It looks like you have no OpenGL graphics driver installed.

Can you run other OpenGL programs on your machine?

--
<\___/>
/ O O \
\_____/ FTB. Remove my socks for email address.

Oh ofcourse other programs are running fine on my pc...

its just for this specific program..

ill post the code here::

imageload.cpp:
############################################################
// ImageLoad.cpp

// OpenGL SuperBible

// Demonstrates loading a color image

// Program by Richard S. Wright Jr.





#include<GL/gl.h>
#include<GL/glut.h>
#include <math.h>
#include"tgaload.h"
#include <stdlib.h>





//////////////////////////////////////////////////////////////////

// This function does any needed initialization on the rendering

// context.

void SetupRC()

{

// Black background

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

}





///////////////////////////////////////////////////////////////////////

// Called to draw scene

void RenderScene(void)

{

GLbyte *pImage = NULL;

GLint iWidth, iHeight, iComponents;

GLenum eFormat;



// Clear the window with current clearing color

glClear(GL_COLOR_BUFFER_BIT);



// Targa's are 1 byte aligned

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);



// Load the TGA file, get width, height, and component/format
information

pImage = gltLoadTGA("Fire.tga", &iWidth, &iHeight, &iComponents,
&eFormat);



// Use Window coordinates to set raster position

glRasterPos2i(0, 0);



// Draw the pixmap

if(pImage != NULL)

glDrawPixels(iWidth, iHeight, eFormat, GL_UNSIGNED_BYTE,
pImage);



// Don't need the image data anymore

free(pImage);



// Do the buffer Swap

glutSwapBuffers();

}





//////////////////////////////////////////////////////////////

// For this example, it really doesn't matter what the

// projection is since we are using glWindowPos

void ChangeSize(int w, int h)

{

// Prevent a divide by zero, when window is too short

// (you cant make a window of zero width).

if(h == 0)

h = 1;



glViewport(0, 0, w, h);



// Reset the coordinate system before modifying

glMatrixMode(GL_PROJECTION);

glLoadIdentity();



// Set the clipping volume

gluOrtho2D(0.0f, (GLfloat) w, 0.0, (GLfloat) h);



glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

}



/////////////////////////////////////////////////////////////

// Main program entrypoint

int main(int argc, char* argv[])

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGB | GL_DOUBLE);

glutInitWindowSize(512 ,512);

glutCreateWindow("OpenGL Image Loading");

glutReshapeFunc(ChangeSize);

glutDisplayFunc(RenderScene);



SetupRC();

glutMainLoop();



return 0;

}

############################################################


tgaload.cpp:
############################################################
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include<GL/gl.h>
#include<string.h>
typedef struct
{
GLbyte identsize; // Size of ID field that follows
header (0)
GLbyte colorMapType; // 0 = None, 1 = paletted
GLbyte imageType; // 0 = none, 1 = indexed, 2 = rgb,
3 = grey, +8=rle
unsigned short colorMapStart; // First colour map entry
unsigned short colorMapLength; // Number of colors
unsigned char colorMapBits; // bits per palette entry
unsigned short xstart; // image x origin
unsigned short ystart; // image y origin
unsigned short width; // width in pixels
unsigned short height; // height in pixels
GLbyte bits; // bits per pixel (8 16, 24, 32)
GLbyte descriptor; // image descriptor
} TGAHEADER;
#pragma pack(8)
int gltIsExtSupported(const char *extension)
{
GLubyte *extensions = NULL;
const GLubyte *start;
GLubyte *where, *terminator;

where = (GLubyte *) strchr(extension, ' ');
if (where || *extension == '\0')
return 0;

extensions = (GLubyte *)glGetString(GL_EXTENSIONS);

start = extensions;
for (;;)
{
where = (GLubyte *) strstr((const char *) start, extension);

if (!where)
break;

terminator = where + strlen(extension);

if (where == start || *(where - 1) == ' ')
{
if (*terminator == ' ' || *terminator == '\0')
return 1;
}
start = terminator;
}
return 0;
}

GLint gltWriteTGA(const char *szFileName)
{
FILE *pFile; // File pointer
TGAHEADER tgaHeader; // TGA file header
unsigned long lImageSize; // Size in bytes of image
GLbyte *pBits = NULL; // Pointer to bits
GLint iViewport[4]; // Viewport in pixels
GLenum lastBuffer; // Storage for the current read buffer
setting

// Get the viewport dimensions
glGetIntegerv(GL_VIEWPORT, iViewport);

// How big is the image going to be (targas are tightly packed)
lImageSize = iViewport[2] * 3 * iViewport[3];

// Allocate block. If this doesn't work, go home
pBits = (GLbyte *)malloc(lImageSize);
if(pBits == NULL)
return 0;

// Read bits from color buffer
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);

// Get the current read buffer setting and save it. Switch to
// the front buffer and do the read operation. Finally, restore
// the read buffer state
glGetIntegerv(GL_READ_BUFFER, (GLint *)&lastBuffer);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, iViewport[2], iViewport[3], GL_BGR_EXT,
GL_UNSIGNED_BYTE, pBits);
glReadBuffer(lastBuffer);

// Initialize the Targa header
tgaHeader.identsize = 0;
tgaHeader.colorMapType = 0;
tgaHeader.imageType = 2;
tgaHeader.colorMapStart = 0;
tgaHeader.colorMapLength = 0;
tgaHeader.colorMapBits = 0;
tgaHeader.xstart = 0;
tgaHeader.ystart = 0;
tgaHeader.width = iViewport[2];
tgaHeader.height = iViewport[3];
tgaHeader.bits = 24;
tgaHeader.descriptor = 0;

// Do byte swap for big vs little endian
#ifdef __APPLE__
LITTLE_ENDIAN_WORD(&tgaHeader.colorMapStart);
LITTLE_ENDIAN_WORD(&tgaHeader.colorMapLength);
LITTLE_ENDIAN_WORD(&tgaHeader.xstart);
LITTLE_ENDIAN_WORD(&tgaHeader.ystart);
LITTLE_ENDIAN_WORD(&tgaHeader.width);
LITTLE_ENDIAN_WORD(&tgaHeader.height);
#endif

// Attempt to open the file
pFile = fopen(szFileName, "wb");
if(pFile == NULL)
{
free(pBits); // Free buffer and return error
return 0;
}

// Write the header
fwrite(&tgaHeader, sizeof(TGAHEADER), 1, pFile);

// Write the image data
fwrite(pBits, lImageSize, 1, pFile);

// Free temporary buffer and close the file
free(pBits);
fclose(pFile);

// Success!
return 1;
}



GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint
*iHeight, GLint *iComponents, GLenum *eFormat)
{
FILE *pFile; // File pointer
TGAHEADER tgaHeader; // TGA file header
unsigned long lImageSize; // Size in bytes of image
short sDepth; // Pixel depth;
GLbyte *pBits = NULL; // Pointer to bits

// Default/Failed values
*iWidth = 0;
*iHeight = 0;
*eFormat = GL_BGR_EXT;
*iComponents = GL_RGB8;

// Attempt to open the fil
pFile = fopen(szFileName, "rb");
if(pFile == NULL)
return NULL;

// Read in header (binary)
fread(&tgaHeader, 18/* sizeof(TGAHEADER)*/, 1, pFile);

// Do byte swap for big vs little endian
#ifdef __APPLE__
LITTLE_ENDIAN_WORD(&tgaHeader.colorMapStart);
LITTLE_ENDIAN_WORD(&tgaHeader.colorMapLength);
LITTLE_ENDIAN_WORD(&tgaHeader.xstart);
LITTLE_ENDIAN_WORD(&tgaHeader.ystart);
LITTLE_ENDIAN_WORD(&tgaHeader.width);
LITTLE_ENDIAN_WORD(&tgaHeader.height);
#endif


// Get width, height, and depth of texture
*iWidth = tgaHeader.width;
*iHeight = tgaHeader.height;
sDepth = tgaHeader.bits / 8;

// Put some validity checks here. Very simply, I only understand
// or care about 8, 24, or 32 bit targa's.
if(tgaHeader.bits != 8 && tgaHeader.bits != 24 && tgaHeader.bits !
= 32)
return NULL;

// Calculate size of image buffer
lImageSize = tgaHeader.width * tgaHeader.height * sDepth;

// Allocate memory and check for success
pBits = (GLbyte*)malloc(lImageSize * sizeof(GLbyte));
if(pBits == NULL)
return NULL;

// Read in the bits
// Check for read error. This should catch RLE or other
// weird formats that I don't want to recognize
if(fread(pBits, lImageSize, 1, pFile) != 1)
{
free(pBits);
return NULL;
}
}
############################################################


tgaload.h::
############################################################


int gltIsExtSupported(const char *extension);
GLint gltWriteTGA(const char *szFileName);
GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint
*iHeight, GLint *iComponents, GLenum *eFormat);
############################################################


Thanks.
.



Relevant Pages

  • Re: CreateProcess SW_HIDE not working
    ... In fact all the code works great except the stupid window ... char ipfile; ... There is no bounds checking to see that the buffer is not overrun, ... since there is no reason to use fixed-size char buffers in modern programming. ...
    (microsoft.public.vc.mfc)
  • Re: In window mode, pD3DDevice->SetViewport?
    ... the back buffer is always stretchblit to ... // Holds Our Window Handle ... HINSTANCE hInstance; // Holds The Instance Of The Application ... void ReSizeD3DScene(int width, int height) // Resize And Initialize The ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: A mailslot question
    ... the same problem exists whether you use a single buffer or multiple ... buffers - if you have a bug in your code it will leak memory or else ... processing of a mail slot messages by consuming additional system resources ... the right window dynamically. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Multiple windows and multithreading
    ... > window in separate thread. ... device with a back buffer sized to the full screen. ... ReleaseD3DDevice -- This is called at the end of the window's render proc. ... It would be smarter to call GetD3DDevice with cxClient and cyClient. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Suggestion for TPU: revert
    ... MAIN window has been offered. ... command "delete ", ... If the buffer was modified, ... >> features of EVE, is its extendablity. ...
    (comp.os.vms)