Jump to content
  • Advertisement
Sign in to follow this  
kenkie_gl

something wrong with the code in redbook that i test

This topic is 3642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

the code below can be compiled ,but when i running the .exe ,it failed. i have no idea about it. #include <stdlib.h> #include<stdio.h> #include<GL/glew.h> #include <GL/glut.h> #pragma comment(lib,"glew32.lib") GLubyte *pixels; GLsizei width, height; GLubyte* readImage( const char* filename, GLsizei* width_, GLsizei *height_ ) { int n; GLubyte *pixels_; FILE* infile = fopen( filename, "rb" ); if ( !infile ) { fprintf( stderr, "Unable to open file '%s'\n", filename ); system("pause"); } fread( width_, sizeof( GLsizei ), 1, infile ); fread( height_, sizeof( GLsizei ), 1, infile ); n = 3 * (*width_) * (*height_); pixels_ = (GLubyte *) malloc( n * sizeof( GLubyte )); if ( !pixels_ ) { fprintf( stderr, "Unable to malloc() bytes for pixels\n" ); system("pause"); } fread( pixels_, sizeof( GLubyte ), n, infile ); fclose( infile ); return pixels_; } void init(void) { int i; GLubyte colorTable[256][3]; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glClearColor(0.0, 0.0, 0.0, 0.0); /* Set up an inverse color table */ for ( i = 0; i < 256; ++i ) { colorTable[0] = 255 - i; colorTable[1] = 255 - i; colorTable[2] = 255 - i; } glColorTable(GL_COLOR_TABLE, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, colorTable); glEnable(GL_COLOR_TABLE); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glRasterPos2i( 1, 1 ); glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels ); glFlush(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho (0, w, 0, h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); } } /* Main Loop * Open window with initial window size, title bar, * RGBA display mode, and handle input events. */ int main(int argc, char** argv) { pixels = readImage("F:\\leeds.bin ", &width, &height); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(width, height); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glewInit(); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutMainLoop(); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
What do you mean "failed"? What did you expect would happen, and what actually happened? Did the program crash? Did you get an error message? If so, what was it?

In short, we need more details to help you.

Share this post


Link to post
Share on other sites
You can get all the source files from http://www.opengl-redbook.com/source/
Then,you can get three code files,colortable.c readimage.c and leeds.bin.
Building the program with them,and you will know my doubt.
Help me,thanks!

Share this post


Link to post
Share on other sites
Like Gage64 said, you must specify how it "failed" (Program crash? Error messages? what happened?)
You cannot expect everybody to compile the source to see how it fails.

For example, think if somebody says:
Person A: "I compiled a new distro of linux, and it failed"
Person B: "How it failed?"
Person A: "Download it from www.somelinuxdistro.com, and compile it to see how it fails" (not to mention that the compilation takes 5 hours).

Share this post


Link to post
Share on other sites
My psychic powers tell me that the glut and/or glew dlls aren't in your path. Try putting them in the same folder as the exe.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!