Exemple #1
0
void GLWidget::setModel(Model* model)
{
    clear();
    _model = model;
    createDisplayLists();

    // Set distance's camera and increment step.
    float size = _model->getSize();
    _cameraDistance = size;
    _cameraIncrement = size / 10.0;
    setCamera();

    updateGL();
}
// Constructor. Copy the provided picoSurface_t structure into this object
RenderablePicoSurface::RenderablePicoSurface(picoSurface_t* surf,
											 const std::string& fExt)
: _shaderName(""),
  _dlRegular(0),
  _dlProgramVcol(0),
  _dlProgramNoVCol(0)
{
	// Get the shader from the picomodel struct. If this is a LWO model, use
	// the material name to select the shader, while for an ASE model the
	// bitmap path should be used.
	picoShader_t* shader = PicoGetSurfaceShader(surf);
	std::string rawName = "";

	if (shader != 0)
	{
		if (fExt == "lwo")
		{
			_shaderName = PicoGetShaderName(shader);
		}
		else if (fExt == "ase")
		{
			rawName = PicoGetShaderName(shader);
			std::string rawMapName = PicoGetShaderMapName(shader);
			_shaderName = cleanupShaderName(rawMapName);
		}
	}

	// If shader not found, fallback to alternative if available
	// _shaderName is empty if the ase material has no BITMAP
	// materialIsValid is false if _shaderName is not an existing shader
	if ((_shaderName.empty() || !GlobalMaterialManager().materialExists(_shaderName)) &&
		!rawName.empty())
	{
		_shaderName = cleanupShaderName(rawName);
	}

	// Capturing the shader happens later on when we have a RenderSystem reference

    // Get the number of vertices and indices, and reserve capacity in our
    // vectors in advance by populating them with empty structs.
    int nVerts = PicoGetSurfaceNumVertexes(surf);
    _nIndices = PicoGetSurfaceNumIndexes(surf);
    _vertices.resize(nVerts);
    _indices.resize(_nIndices);

    // Stream in the vertex data from the raw struct, expanding the local AABB
    // to include each vertex.
    for (int vNum = 0; vNum < nVerts; ++vNum) {

    	// Get the vertex position and colour
		Vertex3f vertex(PicoGetSurfaceXYZ(surf, vNum));

		// Expand the AABB to include this new vertex
    	_localAABB.includePoint(vertex);

    	_vertices[vNum].vertex = vertex;
    	_vertices[vNum].normal = Normal3f(PicoGetSurfaceNormal(surf, vNum));
    	_vertices[vNum].texcoord = TexCoord2f(PicoGetSurfaceST(surf, 0, vNum));
    	_vertices[vNum].colour =
    		getColourVector(PicoGetSurfaceColor(surf, 0, vNum));
    }

    // Stream in the index data
    picoIndex_t* ind = PicoGetSurfaceIndexes(surf, 0);
    for (unsigned int i = 0; i < _nIndices; i++)
    	_indices[i] = ind[i];

	// Calculate the tangent and bitangent vectors
	calculateTangents();

	// Construct the DLs
	createDisplayLists();
}
Exemple #3
0
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitWindowPosition(10, 10);
	glutInitWindowSize(800+GAP*3, 400+GAP*2);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	if ((estado.mainWindow=glutCreateWindow("Labirinto")) == GL_FALSE)
		exit(1);

	imprime_ajuda();

	// Registar callbacks do GLUT da janela principal
	init();
	glutReshapeFunc(reshapeMainWindow);
	glutDisplayFunc(displayMainWindow);

	glutTimerFunc(estado.timer,Timer,0);
	glutKeyboardFunc(Key);
	glutKeyboardUpFunc(KeyUp);
	glutSpecialFunc(SpecialKey);
	glutSpecialUpFunc(SpecialKeyUp);

	// criar a sub window topSubwindow
	estado.topSubwindow=glutCreateSubWindow(estado.mainWindow, GAP, GAP, 400, 400);
	init();
	setLight();
	setMaterial();
	createTextures(modelo.texID[JANELA_TOP]);
	createDisplayLists(JANELA_TOP);

	mdlviewer_init("gordon.mdl", gordon.stdModel[JANELA_TOP] );

	for(int i=0;i<3;i++)
		mdlviewer_init("headcrab.mdl", headCrabs[i].stdModel[JANELA_TOP] );

	glutReshapeFunc(redisplayTopSubwindow);
	glutDisplayFunc(displayTopSubwindow);

	glutTimerFunc(estado.timer,Timer,0);
	glutKeyboardFunc(Key);
	glutSpecialFunc(SpecialKey);
	glutSpecialUpFunc(SpecialKeyUp);


	// criar a sub window navigateSubwindow
	estado.navigateSubwindow=glutCreateSubWindow(estado.mainWindow, 400+GAP, GAP, 400, 800);
	init();
	setLight();
	setMaterial();

	createTextures(modelo.texID[JANELA_NAVIGATE]);
	createDisplayLists(JANELA_NAVIGATE);
	mdlviewer_init("gordon.mdl", gordon.stdModel[JANELA_NAVIGATE] );

	for(int i=0;i<3;i++)
		mdlviewer_init("headcrab.mdl", headCrabs[i].stdModel[JANELA_NAVIGATE] );

	glutReshapeFunc(reshapeNavigateSubwindow);
	glutDisplayFunc(displayNavigateSubwindow);
	glutMouseFunc(mouseNavigateSubwindow);

	glutTimerFunc(estado.timer,Timer,0);
	glutKeyboardFunc(Key);
	glutSpecialFunc(SpecialKey);
	glutSpecialUpFunc(SpecialKeyUp);


	glutMainLoop();
	return 0;

}
Exemple #4
0
void View3d::initializeGL() {
  glEnable(GL_DEPTH_TEST);
  glEnable (GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  emit createDisplayLists();
}
Exemple #5
0
int main ( int argc, char** argv )
{
    // Initialize world.

    DYN_initialize(&world, 0.02);
    {
        DYN_Body body;
        DYN_BodyStaticAttributes attributes;

        double nullVector[3] = {0, 0, 0};
        double identity[9] =
        {
            1, 0, 0,
            0, 1, 0,
            0, 0, 1
        };

//        double impulse[3] = {100, 0, 0};
//        double pointOfImpulse[3] = {0, 1, 1};

        attributes.shape = DYN_BS_CUBOID;
        attributes.cuboidAttributes.width = 3;
        attributes.cuboidAttributes.height = 3;
        attributes.cuboidAttributes.depth = 3;

        DYN_calculateMass(&attributes, 1);

        memcpy(body.position, nullVector, sizeof(nullVector));
        memcpy(body.velocity, nullVector, sizeof(nullVector));
        memcpy(body.angularVelocity, nullVector, sizeof(nullVector));
        memcpy(body.orientation, identity, sizeof(identity));

        DYN_addBody(&world, &body, &attributes);

        //applyImpulse(&world, &world.bodies[0], pointOfImpulse, impulse);


/*        attributes.cuboidAttributes.width = 1;
        attributes.cuboidAttributes.height = 1;
        attributes.cuboidAttributes.depth = 1;
        DYN_calculateMass(&attributes, 1);
        body.position[0] = 0;
        body.position[1] = 0;
        body.position[2] = -100;
        body.velocity[2] = 1;
        DYN_addBody(&world, &body, &attributes);*/

        {
            int i,j,k;
            attributes.cuboidAttributes.width = 3;
            attributes.cuboidAttributes.height = 3;
            attributes.cuboidAttributes.depth = 3;
            DYN_calculateMass(&attributes, 1);
            for (i = 0; i < 4; i++)
            {
                for (j = 0; j < 4; j++)
                {
                    for (k = 0; k < 4; k++)
                    {
                        body.position[0] = 10 + 5*i;
                        body.position[1] = 10 + 5*j;
                        body.position[2] = 10 + 5*k;
                        memcpy(body.velocity, nullVector, sizeof(nullVector));
                        DYN_addBody(&world, &body, &attributes);
                    }
                }
            }
        }
    }

    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }

    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    // Setting OpenGL  attributes

    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

    // create a new window
    SDL_Surface* screen = SDL_SetVideoMode(RESOLUTION_X, RESOLUTION_Y, 16,
                                           SDL_HWSURFACE | SDL_OPENGL);

    // Lock mouse in

    SDL_ShowCursor(0);
    //SDL_WM_GrabInput(SDL_GRAB_ON); //< Toggle this

    // Create display lists

    createDisplayLists();

    // Initialize modes

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL);

    // Initialize gl matrixes

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, 4.0/3.0, 1, 100000.0);

    // Initlalize GL lights

    {
        GLfloat ambient[4] = {0.1, 0.1, 0.1, 1};

        GLfloat diffuseColor[4] = {1, 1, 1, 1};
        GLfloat specularColor[4] = {0,0,0,0};

        glEnable(GL_LIGHTING);
        glEnable(GL_CULL_FACE);
        glEnable(GL_LIGHT0);

        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);

        glMatrixMode(GL_MODELVIEW);

        glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor);
        glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
        glLightfv(GL_LIGHT0, GL_SPECULAR, specularColor);
        glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0);

    }


    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

    // program main loop
    while (!handleEvents())
    {
        // message processing loop

        DYN_stepWorld(&world);
        controlView();
        draw();
        usleep(20000);

        // finally, update the screen
        SDL_GL_SwapBuffers();
    } // end main loop

    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}