Определение состава и структуры автоматизированной системы визуализации технологических процессов, страница 6

 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // If the u,v coordinates overflow the range 0,1 the image is repeated

 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The magnification function ("linear" produces better results)

 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //The minifying function

 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // We don't combine the color with the original surface color, use only the texture map.

 // Finally we define the 2d texture

 glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);

 // And create 2d mipmaps for the minifying function

 gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);

 free(l_texture); // Free the memory we used to load the texture

 return (num_texture); // Returns the current texture OpenGL ID

}


Приложение 3 (Рисование 3д модели)

#include <windows.h>

#include <GL/glut.h>

#include "tutorial4.h"

#include "texture.h"

#include "3dsloader.h"

/**********************************************************

 *

 * VARIABLES DECLARATION

 *

 *********************************************************/

// The width and height of your window, change them as you like

int screen_width=640;

int screen_height=480;

// Absolute rotation values (0-359 degrees) and rotation increments for each frame

double rotation_x=0, rotation_x_increment=0.1;

double rotation_y=0, rotation_y_increment=0.05;

double rotation_z=0, rotation_z_increment=0.03;

double scale_x = 1;

double scale_y = 1;

double scale_z = 1;

/*

double rotation_x = 0, rotation_x_increment = 0.0;

double rotation_y = 0, rotation_y_increment = 0.0;

double rotation_z = 0, rotation_z_increment = 0.0;

*/

// Flag for rendering as lines or filled polygons

int filling=1; //0=OFF 1=ON

//generic object

obj_type object;

/**********************************************************

 *

 * SUBROUTINE init()

 *

 * Used to initialize OpenGL and to setup our world

 *

 *********************************************************/

void init(void)

{

 glClearColor(0.0, 0.0, 0.0, 0.0); // This clear the background color to black

 glShadeModel(GL_SMOOTH); // Type of shading for the polygons

 // Viewport transformation

 glViewport(0,0,screen_width,screen_height); 

 // Projection transformation

 glMatrixMode(GL_PROJECTION); // Specifies which matrix stack is the target for matrix operations

 glLoadIdentity(); // We initialize the projection matrix as identity

 gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f); // We define the "viewing volume"

 glEnable(GL_DEPTH_TEST); // We enable the depth test (also called z buffer)

 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)

 glEnable(GL_TEXTURE_2D); // This Enable the Texture mapping

 /**************************!!!!!!!!!!!!!!!!!!!

 SO HERE THE FILE NAME GOES*/

 Load3DS (&object,"file.3ds");

 //Load3DS (&object,"pizza.3ds");

 // AHD HERE IS TEXTURE

 object.id_texture=LoadBitmap("file.bmp"); // The Function LoadBitmap() return the current texture ID

 //object.id_texture=LoadBitmap("pizza.bmp"); // The Function LoadBitmap() return the current texture ID

 // If the last function returns -1 it means the file was not found so we exit from the program

 if (object.id_texture==-1)

 {

 MessageBox(NULL,"Image file: texture not found", "Zetadeck",MB_OK | MB_ICONERROR);

 exit (0);

 }

}

/**********************************************************

 *

 * SUBROUTINE resize(int,int)

 *