2013-10-03 77 views
1

我試圖運行代碼塊12.11此代碼,並不斷收到此錯誤:fprintf中並不在此範圍內fprintf中不在此範圍內聲明

# include <GL/glew.h> 
# include <GL/freeglut.h> 


using namespace std; 

//any time the window is resized, this function is called. It set up to the 
// "glutReshapeFunc" in Maine. 
void changeViewport(int w, int h) { 
    glViewport(0, 0, w, h); 
} 

//Here is the function that gets called each time the window needs to be redrawn. 
//It is the "paint" method for our program, and it is set up from the glutDisplayFunc in   main. 
void render() { 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glutSwapBuffers(); 
} 

int main (int argc, char** argv) { 
//Initialize GLUT 
glutInit(&argc, argv); 

//Set up some memory buffers for our display 
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 
//set the window size 
glutInitWindowSize(900, 600); 
//Create the window with the title "Hello, GL" 
glutCreateWindow("Hello, GL"); 
//Bind the two functions (above) to respond when necessary 
glutReshapeFunc(changeViewport); 
glutDisplayFunc(render); 

//Very important! This initializes the entry points in the OpenGL driver so we can 
//call functions in the API. 
GLenum err = glewInit(); 
if (GLEW_OK != err) { 
    fprintf(stderr, "GLEW error"); 
    return 1; 
} 

//Start up a loop that runs in the background (you never see it). 
glutMainLoop(); 
return 0; 
} 

我不確定,不知道該做什麼聲明。如果有人有任何想法,請讓我知道。

回答

3

#include <stdio.h> 

在你的文件的頂部。這就是printf及其變體所在的地方。