int main() { viewport_t *viewport; int last_x, last_y; pthread_attr_t attr; pthread_t tid; int i; GLfloat ratio; static GLfloat light_position[] = { 5.0, 5.0, 10.0, 0.0 }; static GLfloat diffuse_light[] = { 1.0, 1.0, 1.0, 1.0 }; //printf("main 1\n"); viewport = new_viewport(1280, 1024); //printf("main 2\n"); viewport->xrot = 20.0; viewport->yrot = 30.0; viewport->zoom = -40.0; //#if UNFINISHED // Initialize OpenGL // From the reshape event handler glViewport(0, 0, viewport->w, viewport->h); //printf("main 2\n"); glMatrixMode(GL_PROJECTION); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); ratio = (GLfloat)viewport->h / (GLfloat)viewport->w; //printf("main 2\n"); glFrustum(-1.0, 1.0, -ratio, ratio, 5.0, 600.0); //printf("main 2\n"); glMatrixMode(GL_MODELVIEW); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthMask(GL_FALSE); //printf("main 2\n"); // Initialize texture //#if 0 { png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); png_infop info_ptr = png_create_info_struct(png_ptr); FILE *fd = fopen(TEXTURE_FILE, "rb"); int w; int h; int color_model; unsigned char **row_pointers; unsigned char *data; if(!fd) { printf("Couldn't open %s.\n", TEXTURE_FILE); exit(1); } png_init_io(png_ptr, fd); png_read_info(png_ptr, info_ptr); w = png_get_image_width(png_ptr, info_ptr); h = png_get_image_height(png_ptr, info_ptr); color_model = png_get_color_type(png_ptr, info_ptr); row_pointers = (unsigned char**)calloc(1, sizeof(png_bytep) * h); data = (unsigned char*)calloc(1, w * h * 3); for(i = 0; i < h; i++) row_pointers[i] = data + w * 3 * i; png_read_image(png_ptr, row_pointers); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &viewport->texName); glBindTexture(GL_TEXTURE_2D, viewport->texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, row_pointers[0]); //printf("main 3\n"); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); free(row_pointers); free(data); fclose(fd); } //printf("main 4\n"); //#endif // 0 // Initialize status init_status(&viewport->status); pthread_attr_init(&attr); pthread_create(&tid, &attr, viewport_loop, viewport); // pthread_create(&tid, &attr, texture_loop, viewport); while(!viewport->done) { //printf("main 5\n"); viewport_draw(viewport); // SDL_ScanFrameBuffer(viewport->screen); //printf("main 6 press a key\n"); //getc(stdin); //exit(0); } //#endif // UNFINISHED //printf("main 8\n"); return 0; }
int main() { viewport_t *viewport; int last_x, last_y; pthread_attr_t attr; pthread_t tid; int i; GLfloat ratio; static GLfloat light_position[] = { 5.0, 5.0, 10.0, 0.0 }; static GLfloat diffuse_light[] = { 1.0, 1.0, 1.0, 1.0 }; //printf("main 1\n"); viewport = new_viewport(1280, 1024); //printf("main 2\n"); viewport->xrot = 20.0; viewport->yrot = 30.0; viewport->zoom = -40.0; viewport->x1 = 0; viewport->y1 = 0; viewport->y2 = TEXTURE_SIDE; viewport->x2 = TEXTURE_SIDE; viewport->tex_x1 = 0; viewport->tex_y1 = 0; viewport->tex_x2 = 1; viewport->tex_y2 = 1; //#if UNFINISHED // Initialize OpenGL // From the reshape event handler glViewport(0, 0, viewport->w, viewport->h); //printf("main 2\n"); glMatrixMode(GL_PROJECTION); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); ratio = (GLfloat)viewport->h / (GLfloat)viewport->w; //printf("main 2\n"); glFrustum(-1.0, 1.0, -ratio, ratio, 5.0, 600.0); //printf("main 2\n"); glMatrixMode(GL_MODELVIEW); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); // glShadeModel(GL_SMOOTH); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // glDepthMask(GL_FALSE); //printf("main 2\n"); // Initialize movie { unsigned char **row_pointers; int j, w, h; viewport->frame_size = TEXTURE_SIDE * TEXTURE_SIDE * 4; viewport->total_frames = TOTAL_FRAMES; viewport->movie_data = calloc(1, TEXTURE_SIDE * TEXTURE_SIDE * 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for(i = 0; i < TEXTURE_COUNT; i++) { glGenTextures(1, &viewport->texture[i]); glBindTexture(GL_TEXTURE_2D, viewport->texture[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXTURE_SIDE, TEXTURE_SIDE, 0, GL_RGB, GL_UNSIGNED_BYTE, viewport->movie_data); } //printf("main 3\n"); } viewport->current_frame = 0; viewport->frame_step = 1; //printf("main 4\n"); //#endif // 0 // Initialize status init_status(&viewport->status); viewport_draw(viewport); pthread_attr_init(&attr); pthread_create(&tid, &attr, viewport_loop, viewport); pthread_join(tid, 0); //#endif // UNFINISHED //printf("main 8\n"); return 0; }