Example #1
0
void board::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -24.0);
    glRotatef(rotationX, 1.0, 0.0, 0.0);
    glRotatef(rotationY, 0.0, 1.0, 0.0);
    glRotatef(rotationZ, 0.0, 0.0, 1.0);
//------------------------------------------
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    bindTexture(QImage(":/image/modified.png"));
    glBegin(GL_QUADS);
          // Up face (y = 1.0f)
          qglColor(Qt::white);
          glTexCoord2f(0.0, 0.0);glVertex3f( 10.0f,  10.0f, 1.0f);
          glTexCoord2f(1.0, 0.0);glVertex3f(-10.0f,  10.0f, 1.0f);
          glTexCoord2f(1.0, 1.0);glVertex3f(-10.0f, -10.0f, 1.0f);
          glTexCoord2f(0.0, 1.0);glVertex3f( 10.0f, -10.0f, 1.0f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
          // Bottom face (y = 1.0f)
          qglColor(Qt::white);
          glVertex3f( 10.0f, -10.0f, -1.0f);
          glVertex3f(-10.0f, -10.0f, -1.0f);
          glVertex3f(-10.0f,  10.0f, -1.0f);
          glVertex3f( 10.0f,  10.0f, -1.0f);

          // Front face  (z = 1.0f)
          qglColor(QColor(200,76,70));
          glVertex3f( 10.0f, -10.0f,  1.0f);
          glVertex3f( 0.0f, -10.0f,  1.0f);
          glVertex3f( 0.0f, -10.0f, -1.0f);
          glVertex3f( 10.0f, -10.0f, -1.0f);
          qglColor(QColor(244,188,88));
          glVertex3f( 0.0f, -10.0f,  1.0f);
          glVertex3f(-10.0f, -10.0f,  1.0f);
          glVertex3f(-10.0f, -10.0f, -1.0f);
          glVertex3f( 0.0f, -10.0f, -1.0f);

          // Back face (z = -1.0f)
          qglColor(QColor(35,148,147));
          glVertex3f( 10.0f, 10.0f, -1.0f);
          glVertex3f( 0.0f, 10.0f, -1.0f);
          glVertex3f( 0.0f, 10.0f,  1.0f);
          glVertex3f( 10.0f, 10.0f,  1.0f);
          qglColor(QColor(163,189,110));
          glVertex3f( 0.0f, 10.0f, -1.0f);
          glVertex3f(-10.0f, 10.0f, -1.0f);
          glVertex3f(-10.0f, 10.0f,  1.0f);
          glVertex3f( 0.0f, 10.0f,  1.0f);

          // Right face (x = -1.0f)
          qglColor(QColor(35,148,147));
          glVertex3f(10.0f,  10.0f,  1.0f);
          glVertex3f(10.0f,  0.0f,  1.0f);
          glVertex3f(10.0f,  0.0f, -1.0f);
          glVertex3f(10.0f,  10.0f, -1.0f);
          qglColor(QColor(200,76,70));
          glVertex3f(10.0f,  0.0f,  1.0f);
          glVertex3f(10.0f, -10.0f,  1.0f);
          glVertex3f(10.0f, -10.0f, -1.0f);
          glVertex3f(10.0f,  0.0f, -1.0f);

          // Left face (x = 1.0f)
          qglColor(QColor(163,189,110));
          glVertex3f(-10.0f,  0.0f,  1.0f);
          glVertex3f(-10.0f,  10.0f,  1.0f);
          glVertex3f(-10.0f,  10.0f, -1.0f);
          glVertex3f(-10.0f,  0.0f, -1.0f);
          qglColor(QColor(244,188,88));
          glVertex3f(-10.0f, -10.0f,  1.0f);
          glVertex3f(-10.0f,  0.0f,  1.0f);
          glVertex3f(-10.0f,  0.0f, -1.0f);
          glVertex3f(-10.0f, -10.0f, -1.0f);
       glEnd();  // End of drawing color-cube

}
////////////////////////////////////////////////////////////////////////////////
//! Run a simple test for CUDA
////////////////////////////////////////////////////////////////////////////////
void
runTest( int argc, char** argv)
{
	ocd_options opts = ocd_get_options();
	platform_id = opts.platform_id;
	n_device = opts.device_id;

	if ( argc != 8)
	{
		printf("Usage: GpuTemporalDataMining [<platform> <device> --] <file path> <temporal constraint path> <threads> <support> <(a)bsolute or (r)atio> <(s)tatic | (d)ynamic> <(m)ap and merge | (n)aive | (o)hybrid> \n");
		return;
	}

//    CUT_DEVICE_INIT();
    initGpu();

    getDeviceVariables(device_id);


	printf("Dataset, Support Threshold, PTPE or MapMerge, A1 or A1+A2, Level, Episodes (N), Episodes Culled (X), A1 Counting Time, A2 Counting Time, Generation Time, Total Counting Time\n");

    //CUT_SAFE_CALL( cutCreateTimer( &timer));
    //CUT_SAFE_CALL( cutCreateTimer( &generating_timer));
    //CUT_SAFE_CALL( cutCreateTimer( &a1_counting_timer));
    //CUT_SAFE_CALL( cutCreateTimer( &a2_counting_timer));
    //CUT_SAFE_CALL( cutCreateTimer( &total_timer));

    //CUT_SAFE_CALL( cutStartTimer( total_timer));
    //CUT_SAFE_CALL( cutStartTimer( timer));
    //CUT_SAFE_CALL( cutStartTimer( generating_timer));
    //CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));
    //CUT_SAFE_CALL( cutStartTimer( a2_counting_timer));

    unsigned int num_threads = atoi(argv[3]);
    // allocate host memory
    //initEpisodeCandidates();
	if ( loadData( argv[1] ) != 0 )
		return;
	if ( loadTemporalConstraints(argv[2]) != 0 )
		return;

	// Check whether value supplied is absolute or ratio support
	supportType = *(argv[5]) == 'a' ? ABSOLUTE : RATIO;
	memoryModel = *(argv[6]) == 's' ? STATIC : DYNAMIC;

	switch (*(argv[7]))
	{
	case 'm':
		algorithmType = MAP_AND_MERGE;
		break;
	case 'n':
		algorithmType = NAIVE;
		break;
	case 'o':
		algorithmType = OPTIMAL;
		break;
	}

	support = atof(argv[4]);

	dumpFile = fopen( "episode.txt", "w" );

	//printf("Initializing GPU Data...\n");

	setupGpu();

	// setup execution parameters
    size_t grid[3];
    size_t threads[3];

	//printf("Event stream size: %i\n", eventSize);

	// BEGIN LOOP
	for ( int level = 1; level <= eventSize; level++ )
	{
		printf("Generating episode candidates for level %i...\n", level);
//		CUT_SAFE_CALL( cutResetTimer( total_timer));
//		CUT_SAFE_CALL( cutStartTimer( total_timer));

		//CUDA_SAFE_CALL( cudaUnbindTexture( candidateTex ) );
		if(level != 1){
			unbindTexture(&candidateTex, d_episodeCandidates, numCandidates * (level-1) * sizeof(UBYTE) );
		//CUDA_SAFE_CALL( cudaUnbindTexture( intervalTex ) );
		unbindTexture(&intervalTex, d_episodeIntervals, numCandidates * (level-2) * 2 * sizeof(float));
        }

//		CUT_SAFE_CALL( cutResetTimer( generating_timer));
//		CUT_SAFE_CALL( cutStartTimer( generating_timer));

//		int test1, test = numCandidates;
//		generateEpisodeCandidatesCPU( level );
//		test1 = numCandidates;
//		numCandidates = test;
        printf("Generating Episodes\n");
#ifdef CPU_EPISODE_GENERATION
		generateEpisodeCandidatesCPU( level );
#else
		generateEpisodeCandidatesGPU( level, num_threads );
#endif

//		CUT_SAFE_CALL( cutStopTimer( generating_timer));
		//printf( "\tGenerating time: %f (ms)\n", cutGetTimerValue( generating_timer));


		if ( numCandidates == 0 )
			break;
        printf("Writing to buffer\n");
		// Copy candidates to GPU
#ifdef CPU_EPISODE_GENERATION
		clEnqueueWriteBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent);
                START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
                END_TIMER(ocdTempTimer)
		clEnqueueWriteBuffer(commands, d_episodeIntervals, CL_TRUE, 0, numCandidates * (level-1) * 2 * sizeof(float), h_episodeIntervals, 0, NULL, &ocdTempEvent);
                clFinish(commands);
		START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
                END_TIMER(ocdTempTimer)
#endif

        bindTexture( 0, &candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE), CL_UNSIGNED_INT8);

		bindTexture( 0, &intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float), CL_FLOAT );

		//printf("Executing kernel on %i candidates...\n", numCandidates, level);

		// execute the kernel
		calculateGrid(grid, num_threads, numCandidates);
		calculateBlock(threads, num_threads, numCandidates);

		int sections;
		unsigned int shared_mem_needed;
		//CUT_SAFE_CALL( cutStartTimer( counting_timer));

		int aType = algorithmType;
		if ( algorithmType == OPTIMAL )
			aType = chooseAlgorithmType( level, numCandidates, num_threads );

		if ( memoryModel == DYNAMIC )
		{
			if ( aType == NAIVE )
			{
				shared_mem_needed = MaxListSize*level*threads[0]*sizeof(float);
                printf("Shared memory needed %d\n", shared_mem_needed);
				//CUT_SAFE_CALL( cutResetTimer( a1_counting_timer));
				//CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));
				countCandidates(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );

			}
			else
			{
                printf("DYNAMIC MAP MERGE\n");
				calculateLevelParameters(level, threads, grid, sections);
				shared_mem_needed = 16000;
                printf("numCandidates=%d\n", numCandidates);
				//CUT_SAFE_CALL( cutResetTimer( a1_counting_timer));
				//CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));
				countCandidatesMapMerge(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );
				//countCandidatesMapMergeStatic<<< grid, threads, shared_mem_needed >>>( d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates );
			}
		}
		else
		{
			if ( aType == NAIVE )
			{
				shared_mem_needed = level*threads[0]*sizeof(float);
			}
			else
			{
				calculateLevelParameters(level, threads, grid, sections);
				shared_mem_needed = 16000;
			}

				//CUT_SAFE_CALL( cutResetTimer( a2_counting_timer));
				//CUT_SAFE_CALL( cutStartTimer( a2_counting_timer));
			if ( aType == NAIVE )
                countCandidatesStatic(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed  );
			else
                countCandidatesMapMergeStatic(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );
			clFinish(commands);

			//CUT_SAFE_CALL( cutStopTimer( a2_counting_timer));

            int err;
            err = clEnqueueReadBuffer(commands,d_episodeSupport, CL_TRUE, 0, numCandidates * sizeof(float), h_episodeSupport, 0, NULL, &ocdTempEvent);
            clFinish(commands);
            	START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer)
            END_TIMER(ocdTempTimer)
		CHKERR(err, "Unable to read buffer from device.");

			unbindTexture(&candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE) );
			unbindTexture(&intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float));

			// Remove undersupported episodes
			cullCandidates( level );

			if ( numCandidates == 0 )
				break;
			unsigned int mmthreads = num_threads;
			if ( MaxListSize*level*num_threads*sizeof(float) > 16384 )
			{
				if ( MaxListSize*level*96*sizeof(float) < 16384 )
					mmthreads = 96;
				else if ( MaxListSize*level*64*sizeof(float) < 16384)
					mmthreads = 64;
				else if ( MaxListSize*level*32*sizeof(float) < 16384)
					mmthreads = 32;
				printf("More shared memory needed for %d threads. Changed to %d threads.\n", num_threads, mmthreads );
			}

#ifdef CPU_EPISODE_GENERATION
            err = clEnqueueWriteBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent);
	START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
            END_TIMER(ocdTempTimer)
            CHKERR(err, "Unable to write buffer 1.");
            if(numCandidates * (level - 1) * 2 * sizeof(float) != 0)
            err = clEnqueueWriteBuffer(commands, d_episodeIntervals, CL_TRUE, 0, numCandidates * (level-1) * 2 * sizeof(float), h_episodeIntervals, 0, NULL, &ocdTempEvent);
        clFinish(commands);
            START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
        CHKERR(err, "Unable to write buffer 2.");
		END_TIMER(ocdTempTimer)
#endif
            bindTexture( 0, &candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE), CL_UNSIGNED_INT8);
            bindTexture( 0, &intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float), CL_FLOAT );

			if ( algorithmType == OPTIMAL )
				aType = chooseAlgorithmType( level, numCandidates, mmthreads );

			// Run (T1,T2] algorithm
			if ( aType == NAIVE )
			{
				shared_mem_needed = MaxListSize*level* mmthreads*sizeof(float);
				calculateGrid(grid, mmthreads, numCandidates );
				calculateBlock(threads, mmthreads, numCandidates );
			}
			else
			{
				calculateLevelParameters(level, threads, grid, sections);
				shared_mem_needed = 16000;
			}
			//CUT_SAFE_CALL( cutResetTimer( a1_counting_timer));
			//CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));

			if ( aType == NAIVE )
                countCandidates(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );
			else
                countCandidatesMapMerge(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );

		}
        printf("Finishing\n");
		clFinish(commands);
		//CUT_SAFE_CALL( cutStopTimer( a1_counting_timer));
		//printf( "\tCounting time: %f (ms)\n", cutGetTimerValue( counting_timer));

		// check if kernel execution generated an error
		//CUT_CHECK_ERROR("Kernel execution failed");

		//printf("Copying result back to host...\n\n");

        int err = clEnqueueReadBuffer(commands, d_episodeSupport, CL_TRUE, 0, numCandidates * sizeof(float), h_episodeSupport, 0, NULL, &ocdTempEvent);
        clFinish(commands);
		START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer)
        END_TIMER(ocdTempTimer)
		CHKERR(err, "Unable to read memory 1.");
		err = clEnqueueReadBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent);
                clFinish(commands);
                START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer)
                END_TIMER(ocdTempTimer)
		CHKERR(err, "Unable to read memory 2.");
		//CUDA_SAFE_CALL( cudaMemcpy( h_mapRecords, d_mapRecords, 3 * numSections * maxLevel * maxCandidates * sizeof(float), cudaMemcpyDeviceToHost ));
		saveResult(level);
		fflush(dumpFile);
	// END LOOP

		//CUT_SAFE_CALL( cutStopTimer( total_timer));

		// Print Statistics for this run
		printf("%s, %f, %s, %s, %d, %d, %d\n",
			argv[1],											// Dataset
			support,											// Support Threshold
			algorithmType == NAIVE ? "PTPE" : algorithmType == MAP_AND_MERGE ? "MapMerge" : "Episode-Based",		// PTPE or MapMerge or Episode-Based
			memoryModel == STATIC ? "A1+A2" : "A1",				// A1 or A1+A2
			level,												// Level
			numCandidates+episodesCulled,						// Episodes counted
			episodesCulled  									// Episodes removed by A2
	//		cutGetTimerValue( a1_counting_timer),				// Time for A1
//			memoryModel == STATIC ? cutGetTimerValue( a2_counting_timer) : 0.0f,				// Time for A2
		//	cutGetTimerValue( generating_timer),				// Episode generation time
		//	cutGetTimerValue( total_timer) );					// Time for total loop
            );
	}
	printf("Done!\n");

    cleanup();

    //CUT_SAFE_CALL( cutStopTimer( timer));
    //printf( "Processing time: %f (ms)\n", cutGetTimerValue( timer));
    //CUT_SAFE_CALL( cutDeleteTimer( timer));
    //CUT_SAFE_CALL( cutDeleteTimer( generating_timer));
    //CUT_SAFE_CALL( cutDeleteTimer( a1_counting_timer));
    //CUT_SAFE_CALL( cutDeleteTimer( a2_counting_timer));
    //CUT_SAFE_CALL( cutDeleteTimer( total_timer));

}
void Traingle::initializeGL()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glClearColor(0.0f,0.0f,0.0f,0.0f);

lightingShaderProgram.addShaderFromSourceFile(QGLShader::Vertex, ":/lightingvertexshader.vsh");
lightingShaderProgram.addShaderFromSourceFile(QGLShader::Fragment, ":/lightingfragmentshader.fsh");
lightingShaderProgram.link();

cubeVertices << QVector3D(-0.5, -0.5, 0.5) << QVector3D( 0.5, -0.5, 0.5) << QVector3D( 0.5, 0.5, 0.5) // Front
    << QVector3D( 0.5, 0.5, 0.5) << QVector3D(-0.5, 0.5, 0.5) << QVector3D(-0.5, -0.5, 0.5)
    << QVector3D( 0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5, 0.5, -0.5) // Back
    << QVector3D(-0.5, 0.5, -0.5) << QVector3D( 0.5, 0.5, -0.5) << QVector3D( 0.5, -0.5, -0.5)
    << QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5, 0.5) << QVector3D(-0.5, 0.5, 0.5) // Left
    << QVector3D(-0.5, 0.5, 0.5) << QVector3D(-0.5, 0.5, -0.5) << QVector3D(-0.5, -0.5, -0.5)
    << QVector3D( 0.5, -0.5, 0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5, 0.5, -0.5) // Right
    << QVector3D( 0.5, 0.5, -0.5) << QVector3D( 0.5, 0.5, 0.5) << QVector3D( 0.5, -0.5, 0.5)
    << QVector3D(-0.5, 0.5, 0.5) << QVector3D( 0.5, 0.5, 0.5) << QVector3D( 0.5, 0.5, -0.5) // Top
    << QVector3D( 0.5, 0.5, -0.5) << QVector3D(-0.5, 0.5, -0.5) << QVector3D(-0.5, 0.5, 0.5)
    << QVector3D(-0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5, 0.5) // Bottom
    << QVector3D( 0.5, -0.5, 0.5) << QVector3D(-0.5, -0.5, 0.5) << QVector3D(-0.5, -0.5, -0.5);


cubeNormals << QVector3D( 0, 0, 1) << QVector3D( 0, 0, 1) << QVector3D( 0, 0, 1) // Front
    << QVector3D( 0, 0, 1) << QVector3D( 0, 0, 1) << QVector3D( 0, 0, 1)
    << QVector3D( 0, 0, -1) << QVector3D( 0, 0, -1) << QVector3D( 0, 0, -1) // Back
    << QVector3D( 0, 0, -1) << QVector3D( 0, 0, -1) << QVector3D( 0, 0, -1)
    << QVector3D(-1, 0, 0) << QVector3D(-1, 0, 0) << QVector3D(-1, 0, 0) // Left
    << QVector3D(-1, 0, 0) << QVector3D(-1, 0, 0) << QVector3D(-1, 0, 0)
    << QVector3D( 1, 0, 0) << QVector3D( 1, 0, 0) << QVector3D( 1, 0, 0) // Right
    << QVector3D( 1, 0, 0) << QVector3D( 1, 0, 0) << QVector3D( 1, 0, 0)
    << QVector3D( 0, 1, 0) << QVector3D( 0, 1, 0) << QVector3D( 0, 1, 0) // Top
    << QVector3D( 0, 1, 0) << QVector3D( 0, 1, 0) << QVector3D( 0, 1, 0)
    << QVector3D( 0, -1, 0) << QVector3D( 0, -1, 0) << QVector3D( 0, -1, 0) // Bottom
    << QVector3D( 0, -1, 0) << QVector3D( 0, -1, 0) << QVector3D( 0, -1, 0);

cubeTextureCoordinates << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Front
    << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
    << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Back
    << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
    << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Left
    << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
    << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Right
    << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
    << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Top
    << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
    << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Bottom
    << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0);


//vertices << QVector3D(1, 0, -2) << QVector3D(0, 1, -2) << QVector3D(-1, 0, -2);
/*vertices << QVector3D(-0.5, -0.5, 0.5) << QVector3D( 0.5, -0.5, 0.5) << QVector3D( 0.5, 0.5, 0.5) // Front
<< QVector3D( 0.5, 0.5, 0.5) << QVector3D(-0.5, 0.5, 0.5) << QVector3D(-0.5, -0.5, 0.5)
<< QVector3D( 0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5, 0.5, -0.5) // Back
<< QVector3D(-0.5, 0.5, -0.5) << QVector3D( 0.5, 0.5, -0.5) << QVector3D( 0.5, -0.5, -0.5)
<< QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5, 0.5) << QVector3D(-0.5, 0.5, 0.5) // Left
<< QVector3D(-0.5, 0.5, 0.5) << QVector3D(-0.5, 0.5, -0.5) << QVector3D(-0.5, -0.5, -0.5)
<< QVector3D( 0.5, -0.5, 0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5, 0.5, -0.5) // Right
<< QVector3D( 0.5, 0.5, -0.5) << QVector3D( 0.5, 0.5, 0.5) << QVector3D( 0.5, -0.5, 0.5)
<< QVector3D(-0.5, 0.5, 0.5) << QVector3D( 0.5, 0.5, 0.5) << QVector3D( 0.5, 0.5, -0.5) // Top
<< QVector3D( 0.5, 0.5, -0.5) << QVector3D(-0.5, 0.5, -0.5) << QVector3D(-0.5, 0.5, 0.5)
<< QVector3D(-0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5, 0.5) // Bottom
<< QVector3D( 0.5, -0.5, 0.5) << QVector3D(-0.5, -0.5, 0.5) << QVector3D(-0.5, -0.5, -0.5);
*/
/*colors << QVector3D(1, 0, 0) << QVector3D(1, 0, 0) << QVector3D(1, 0, 0) // Front
<< QVector3D(1, 0, 0) << QVector3D(1, 0, 0) << QVector3D(1, 0, 0)
<< QVector3D(1, 0, 0) << QVector3D(1, 0, 0) << QVector3D(1, 0, 0) // Back
<< QVector3D(1, 0, 0) << QVector3D(1, 0, 0) << QVector3D(1, 0, 0)
<< QVector3D(0, 1, 0) << QVector3D(0, 1, 0) << QVector3D(0, 1, 0) // Left
<< QVector3D(0, 1, 0) << QVector3D(0, 1, 0) << QVector3D(0, 1, 0)
<< QVector3D(0, 1, 0) << QVector3D(0, 1, 0) << QVector3D(0, 1, 0) // Right
<< QVector3D(0, 1, 0) << QVector3D(0, 1, 0) << QVector3D(0, 1, 0)
<< QVector3D(0, 0, 1) << QVector3D(0, 0, 1) << QVector3D(0, 0, 1) // Top
<< QVector3D(0, 0, 1) << QVector3D(0, 0, 1) << QVector3D(0, 0, 1)
<< QVector3D(0, 0, 1) << QVector3D(0, 0, 1) << QVector3D(0, 0, 1) // Bottom
<< QVector3D(0, 0, 1) << QVector3D(0, 0, 1) << QVector3D(0, 0, 1);
*/

/*textureCoordinates<< QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Front
                  << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
                  << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Back
                  << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
                  << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Left
                  << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
                  << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Right
                  << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
                  << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Top
                  << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0)
                  << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) // Bottom
                  << QVector2D(1, 1) << QVector2D(0, 1) << QVector2D(0, 0);*/
//
// texture = bindTexture(QPixmap(":/texture.png"));
 cubeTexture = bindTexture(QPixmap(":/texture.png"));

 coloringShaderProgram.addShaderFromSourceFile(QGLShader::Vertex, ":/coloringvertexshader.vsh");
 coloringShaderProgram.addShaderFromSourceFile(QGLShader::Fragment, ":/coloringfragshader.fsh");
 coloringShaderProgram.link();

 spotlightVertices << QVector3D( 0, 1, 0) << QVector3D(-0.5, 0, 0.5) << QVector3D( 0.5, 0, 0.5) // Front
        << QVector3D( 0, 1, 0) << QVector3D( 0.5, 0, -0.5) << QVector3D(-0.5, 0, -0.5) // Back
        << QVector3D( 0, 1, 0) << QVector3D(-0.5, 0, -0.5) << QVector3D(-0.5, 0, 0.5) // Left
        << QVector3D( 0, 1, 0) << QVector3D( 0.5, 0, 0.5) << QVector3D( 0.5, 0, -0.5) // Right
        << QVector3D(-0.5, 0, -0.5) << QVector3D( 0.5, 0, -0.5) << QVector3D( 0.5, 0, 0.5) // Bottom
        << QVector3D( 0.5, 0, 0.5) << QVector3D(-0.5, 0, 0.5) << QVector3D(-0.5, 0, -0.5);

 spotlightColors << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Front
        << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Back
        << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Left
        << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Right
        << QVector3D( 1, 1, 1) << QVector3D( 1, 1, 1) << QVector3D( 1, 1, 1) // Bottom
        << QVector3D( 1, 1, 1) << QVector3D( 1, 1, 1) << QVector3D( 1, 1, 1);


}
Example #4
0
void bindTexture(const TransferFunctionProperty& tfp, const TextureUnit& texUnit) { 
    if (auto tfLayer = tfp.get().getData()) {
        auto transferFunctionGL = tfLayer->getRepresentation<LayerGL>();
        transferFunctionGL->bindTexture(texUnit.getEnum());
    }
}
Example #5
0
 Ptr<TextureCL> bindTexturePtr(const oclMat &mat)
 {
     return Ptr<TextureCL>(new TextureCL(bindTexture(mat), mat.rows, mat.cols, mat.type()));
 }
Example #6
0
void Texture::generateMipmap()
{
	bindTexture(0);
	glGenerateMipmap(GL_TEXTURE_2D);

}
Example #7
0
BackGround::BackGround(ATexture * tex)
{
    bindTexture(tex);
}
Example #8
0
void ssr::QOpenGLPlotter::_load_background_textures()
{
  QImage image_buffer;

  image_buffer = QImage(); 

  // load SSR logo
  QString path_to_image( _path_to_gui_images.c_str() );
  path_to_image.append("/ssr_logo.png");

  image_buffer.load(path_to_image, "PNG");

  if (!image_buffer.isNull()) _ssr_logo_texture = bindTexture(image_buffer);
  else 
    ERROR("Texture \"" << path_to_image.toAscii().data() << "\" not loaded.");

  image_buffer = QImage(); 

  // load source shadow texture
  path_to_image = 
        QString( _path_to_gui_images.c_str() ).append("/source_shadow.png");

  image_buffer.load(path_to_image, "PNG");

  if (!image_buffer.isNull()) 
  {
    _source_shadow_texture = bindTexture(image_buffer);
  }
  else 
    ERROR("Texture \"" << path_to_image.toAscii().data() << "\" not loaded.");

  if (_controller.show_head())
  {
    _plot_listener = true;

    // load listener texture
    image_buffer = QImage();

    path_to_image = 
        QString( _path_to_gui_images.c_str() ).append("/listener.png");

    image_buffer.load(path_to_image, "PNG");

    if (!image_buffer.isNull()) _listener_texture = bindTexture(image_buffer);
    else 
     ERROR("Texture \"" << path_to_image.toAscii().data() << "\" not loaded.");

    // load listener shadow texture
    image_buffer = QImage();

    path_to_image = 
        QString( _path_to_gui_images.c_str() ).append("/listener_shadow.png");

    image_buffer.load(path_to_image, "PNG");

    if (!image_buffer.isNull())
    { 
      _listener_shadow_texture = bindTexture(image_buffer);
    }
    else 
     ERROR("Texture \"" << path_to_image.toAscii().data() << "\" not loaded.");

    // load listener background texture
    image_buffer = QImage();

    path_to_image = 
     QString( _path_to_gui_images.c_str() ).append("/listener_background.png");

    image_buffer.load(path_to_image, "PNG");

    if (!image_buffer.isNull()) 
    {
      _listener_background_texture = bindTexture(image_buffer);
    }
    else 
     ERROR("Texture \"" << path_to_image.toAscii().data() << "\" not loaded.");

  }


}
Example #9
0
void OGLContext::makeObject()
{
    /* Bind Textures */
    for (int j=0; j < 4; ++j)
    {
        textures[j] = bindTexture
                (QPixmap(QString("://gfx/Textures/texture%1.png").arg(j + 1)), GL_TEXTURE_2D);
    }

    /* Global Variables */
    const float global_y = 1.8f;
    const float global_z = 1.5f;

    /* Block A */
    const float blockA_x = 0.5f;
    static const float blockA[6][4][3] =
    {
        {
            {+blockA_x, -global_y, -global_z},
            {-blockA_x, -global_y, -global_z},
            {-blockA_x, +global_y, -global_z},
            {+blockA_x, +global_y, -global_z}
        },
        {
            {+blockA_x, +global_y, -global_z},
            {-blockA_x, +global_y, -global_z},
            {-blockA_x, +global_y, +global_z},
            {+blockA_x, +global_y, +global_z}
        },
        {
            {+blockA_x, -global_y, +global_z},
            {+blockA_x, -global_y, -global_z},
            {+blockA_x, +global_y, -global_z},
            {+blockA_x, +global_y, +global_z}
        },
        {
            {-blockA_x, -global_y, -global_z},
            {-blockA_x, -global_y, +global_z},
            {-blockA_x, +global_y, +global_z},
            {-blockA_x, +global_y, -global_z}
        },
        {
            {+blockA_x, -global_y, +global_z},
            {-blockA_x, -global_y, +global_z},
            {-blockA_x, -global_y, -global_z},
            {+blockA_x, -global_y, -global_z}
        },
        {
            {-blockA_x, -global_y, +global_z},
            {+blockA_x, -global_y, +global_z},
            {+blockA_x, +global_y, +global_z},
            {-blockA_x, +global_y, +global_z}
        }
    };

    for (int i = 0; i < 6; ++i)
    {
        for (int j = 0; j < 4; ++j)
        {
            texCoords.append
                    (QVector2D(j == 0 || j == 3, j == 0 || j == 1));
            vertices.append
                    (QVector3D((2.0f * blockA[i][j][0]) - 6.5f, 2.0f * blockA[i][j][1], 2.0f * blockA[i][j][2]));

        }
    }
    /* End Block A */

    /* Block B */
    const float blockB_x = 1.7f;
    const float blockB_z = 1.2f;
    static const float blockB[6][4][3] =
    {
        {
            {+blockB_x, -global_y, -blockB_z},
            {-blockB_x, -global_y, -blockB_z},
            {-blockB_x, +global_y, -blockB_z},
            {+blockB_x, +global_y, -blockB_z}
        },
        {
            {+blockB_x, +global_y, -blockB_z},
            {-blockB_x, +global_y, -blockB_z},
            {-blockB_x, +global_y, +blockB_z},
            {+blockB_x, +global_y, +blockB_z}
        },
        {
            {+blockB_x, -global_y, +blockB_z},
            {+blockB_x, -global_y, -blockB_z},
            {+blockB_x, +global_y, -blockB_z},
            {+blockB_x, +global_y, +blockB_z}
        },
        {
            {-blockB_x, -global_y, -blockB_z},
            {-blockB_x, -global_y, +blockB_z},
            {-blockB_x, +global_y, +blockB_z},
            {-blockB_x, +global_y, -blockB_z}
        },
        {
            {+blockB_x, -global_y, +blockB_z},
            {-blockB_x, -global_y, +blockB_z},
            {-blockB_x, -global_y, -blockB_z},
            {+blockB_x, -global_y, -blockB_z}
        },
        {
            {-blockB_x, -global_y, +blockB_z},
            {+blockB_x, -global_y, +blockB_z},
            {+blockB_x, +global_y, +blockB_z},
            {-blockB_x, +global_y, +blockB_z}
        }
    };

    for (int i = 0; i < 6; ++i)
    {
        for (int j = 0; j < 4; ++j)
        {
            texCoords.append
                    (QVector2D(j == 0 || j == 3, j == 0 || j == 1));
            vertices.append
                    (QVector3D(2.0f * blockB[i][j][0] - 2.2f, 2.0f * blockB[i][j][1], 2.0f * blockB[i][j][2]));}
    }
    /* End Block B */

    /* Block C p1 */
    const float blockCp1_x = 0.6f;
    static const float blockCp1[6][4][3] =
    {
        {
            {+blockCp1_x, -global_y, -global_z},
            {-blockCp1_x, -global_y, -global_z},
            {-blockCp1_x, +global_y, -global_z},
            {+blockCp1_x, +global_y, -global_z}
        },
        {
            {+blockCp1_x, +global_y, -global_z},
            {-blockCp1_x, +global_y, -global_z},
            {-blockCp1_x, +global_y, +global_z},
            {+blockCp1_x, +global_y, +global_z}
        },
        {
            {+blockCp1_x, -global_y, +global_z},
            {+blockCp1_x, -global_y, -global_z},
            {+blockCp1_x, +global_y, -global_z},
            {+blockCp1_x, +global_y, +global_z}
        },
        {
            {-blockCp1_x, -global_y, -global_z},
            {-blockCp1_x, -global_y, +global_z},
            {-blockCp1_x, +global_y, +global_z},
            {-blockCp1_x, +global_y, -global_z}
        },
        {
            {+blockCp1_x, -global_y, +global_z},
            {-blockCp1_x, -global_y, +global_z},
            {-blockCp1_x, -global_y, -global_z},
            {+blockCp1_x, -global_y, -global_z}
        },
        {
            {-blockCp1_x, -global_y, +global_z},
            {+blockCp1_x, -global_y, +global_z},
            {+blockCp1_x, +global_y, +global_z},
            {-blockCp1_x, +global_y, +global_z}
        }
    };

    for (int i = 0; i < 6; ++i)
    {
        for (int j = 0; j < 4; ++j)
        {
            texCoords.append
                    (QVector2D(j == 0 || j == 3, j == 0 || j == 1));
            vertices.append
                    (QVector3D((2.0f * blockCp1[i][j][0]) + 2.4f, 2.0f * blockCp1[i][j][1], 2.0f * blockCp1[i][j][2]));
        }
    }
    /* End Block C p1 */

    /* Block C p2 */
    const float blockCp2_x = 0.2f;
    static const float blockCp2[5][4][3] =
    {
        {
            {+blockCp2_x, -global_y, 0.0f},
            {-1.0f, -global_y, - global_z},
            {-1.0f, +global_y, - global_z},
            {+blockCp2_x, +global_y, 0.0f}
        },
        {
            {+blockCp2_x, +global_y, 0.0f},
            {-1.0f, +global_y, - global_z},
            {-1.0f, +global_y, + global_z},
            {+blockCp2_x, +global_y, 0.0f}
        },
        {
            {-1.0f, -global_y, -global_z},
            {-1.0f, -global_y, + global_z},
            {-1.0f, +global_y, + global_z},
            {-1.0f, +global_y, - global_z}
        },
        {
            {+blockCp2_x, -global_y, 0.0f},
            {-1.0f, -global_y, + global_z},
            {-1.0f, -global_y, - global_z},
            {+blockCp2_x, -global_y, 0.0f}
        },
        {
            {-1.0f, -global_y, +global_z},
            {+blockCp2_x, -global_y, 0.0f},
            {+blockCp2_x, +global_y, 0.0f},
            {-1.0f, +global_y, +global_z}
        }
    };

    for (int i = 0; i < 5; ++i)
    {
        for (int j = 0; j < 4; ++j)
        {
            texCoords.append
                    (QVector2D(j == 0 || j == 3, j == 0 || j == 1));
            vertices.append
                    (QVector3D((2.0f * blockCp2[i][j][0]) + 5.6f, 2.0f * blockCp2[i][j][1], 2.0f * blockCp2[i][j][2]));
        }
    }
    /* End Block C p1 */

    /* Roof block */
    const float roof_x = 3.5f;
    const float roof_y = 0.7f;
    const float roof_indent = 0.2f;
    static const float coords3[5][4][3] =
    {
        {
            {+roof_x, -roof_y, 0.0f},
            {-roof_x, -roof_y, 0.0f},
            {-roof_x, +roof_y, -(global_z + roof_indent)},
            {+roof_x, +roof_y, -(global_z + roof_indent)}
        },
        {
            {+roof_x, +roof_y, -(global_z + roof_indent)},
            {-roof_x, +roof_y, -(global_z + roof_indent)},
            {-roof_x, +roof_y, +(global_z + roof_indent)},
            {+roof_x, +roof_y, +(global_z + roof_indent)}
        },
        {
            {-roof_x, +roof_y, -(global_z + roof_indent)},
            {-roof_x, -roof_y, 0.0f},
            {-roof_x, -roof_y, 0.0f},
            {-roof_x, +roof_y, +(global_z + roof_indent)}
        },
        {
            {+roof_x, +roof_y, +(global_z + roof_indent)},
            {+roof_x, -roof_y, 0.0f},
            {+roof_x, -roof_y, 0.0f},
            {+roof_x, +roof_y, -(global_z + roof_indent)}
        },
        {
            {-roof_x, -roof_y, 0.0f},
            {+roof_x, -roof_y, 0.0f},
            {+roof_x, +roof_y, +(global_z + roof_indent)},
            {-roof_x, +roof_y, +(global_z + roof_indent)}
        }
    };

    for (int i = 0; i < 5; ++i)
    {
        for (int j = 0; j < 4; ++j)
        {
            if (i == 2 || i == 3)
            {
                if (j == 0)
                {
                    texCoords.append(QVector2D(0, 0));
                }
                else if (j == 1 || j == 2)
                {
                    texCoords.append(QVector2D(0.5, 1));
                }
                else if (j == 3)
                {
                    texCoords.append(QVector2D(1, 0));
                }
            }
            else
            {
                texCoords.append(QVector2D(j == 0 || j == 3, j == 0 || j == 1));
            }
            vertices.append
                    (QVector3D((2.0f * coords3[i][j][0]) - 0.9f, (2.0f * coords3[i][j][1]) - 5.0f,
                    2.0f * coords3[i][j][2]));
        }
    }
    /* End Roof block */
}
Example #10
0
	void ChallengeViewer::sceneCompletedHook()
	{
		// create a map with names and scores
		qglColor(Qt::black);
		QMultiMap<int, QStringList> scores;
		for (World::ObjectsIterator it = world->objects.begin(); it != world->objects.end(); ++it)
		{
			AsebaFeedableEPuck *epuck = dynamic_cast<AsebaFeedableEPuck*>(*it);
			if (epuck)
			{
				QStringList entry;
				entry << epuck->name << QString::number(epuck->port) << QString::number((int)epuck->energy) << QString::number((int)epuck->score);
				scores.insert((int)epuck->score, entry);
				renderText(epuck->pos.x, epuck->pos.y, 10, epuck->name, labelFont);
			}
		}
		
		// build score texture
		QImage scoreBoard(512, 256, QImage::Format_ARGB32);
		scoreBoard.setDotsPerMeterX(2350);
		scoreBoard.setDotsPerMeterY(2350);
		QPainter painter(&scoreBoard);
		//painter.fillRect(scoreBoard.rect(), QColor(224,224,255,196));
		painter.fillRect(scoreBoard.rect(), QColor(224,255,224,196));
		
		// draw lines
		painter.setBrush(Qt::NoBrush);
		QPen pen(Qt::black);
		pen.setWidth(2);
		painter.setPen(pen);
		painter.drawRect(scoreBoard.rect());
		pen.setWidth(1);
		painter.setPen(pen);
		painter.drawLine(22, 34, 504, 34);
		painter.drawLine(312, 12, 312, 247);
		painter.drawLine(312, 240, 504, 240);
		
		// draw title
		painter.setFont(titleFont);
		painter.drawText(35, 28, "name");
		painter.drawText(200, 28, "port");
		painter.drawText(324, 28, "energy");
		painter.drawText(430, 28, "points");
		
		// display entries
		QMapIterator<int, QStringList> it(scores);
		
		it.toBack();
		int pos = 61;
		while (it.hasPrevious())
		{
			it.previous();
			painter.drawText(200, pos, it.value().at(1));
			pos += 24;
		}
		
		it.toBack();
		painter.setFont(entryFont);
		pos = 61;
		while (it.hasPrevious())
		{
			it.previous();
			painter.drawText(35, pos, it.value().at(0));
			painter.drawText(335, pos, it.value().at(2));
			painter.drawText(445, pos, it.value().at(3));
			pos += 24;
		}
		
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		GLuint tex = bindTexture(scoreBoard, GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
		glCullFace(GL_FRONT);
		glColor4d(1, 1, 1, 0.75);
		for (int i = 0; i < 4; i++)
		{
			glPushMatrix();
			glTranslated(world->w/2, world->h/2, 50);
			glRotated(90*i, 0, 0, 1);
			glBegin(GL_QUADS);
			glTexCoord2d(0, 0);
			glVertex3d(-20, -20, 0);
			glTexCoord2d(1, 0);
			glVertex3d(20, -20, 0);
			glTexCoord2d(1, 1);
			glVertex3d(20, -20, 20);
			glTexCoord2d(0, 1);
			glVertex3d(-20, -20, 20);
			glEnd();
			glPopMatrix();
		}
		
		glCullFace(GL_BACK);
		glColor3d(1, 1, 1);
		for (int i = 0; i < 4; i++)
		{
			glPushMatrix();
			glTranslated(world->w/2, world->h/2, 50);
			glRotated(90*i, 0, 0, 1);
			glBegin(GL_QUADS);
			glTexCoord2d(0, 0);
			glVertex3d(-20, -20, 0);
			glTexCoord2d(1, 0);
			glVertex3d(20, -20, 0);
			glTexCoord2d(1, 1);
			glVertex3d(20, -20, 20);
			glTexCoord2d(0, 1);
			glVertex3d(-20, -20, 20);
			glEnd();
			glPopMatrix();
		}
		
		deleteTexture(tex);
		
		glDisable(GL_TEXTURE_2D);
		glColor4d(7./8.,7./8.,1,0.75);
		glPushMatrix();
		glTranslated(world->w/2, world->h/2, 50);
		glBegin(GL_QUADS);
		glVertex3d(-20,-20,20);
		glVertex3d(20,-20,20);
		glVertex3d(20,20,20);
		glVertex3d(-20,20,20);
		
		glVertex3d(-20,20,0);
		glVertex3d(20,20,0);
		glVertex3d(20,-20,0);
		glVertex3d(-20,-20,0);
		glEnd();
		glPopMatrix();
		
		// save image
		static int imageCounter = 0;
		if (savingVideo)
			grabFrameBuffer().save(QString("frame%0.bmp").arg(imageCounter++), "BMP");
	}
Example #11
0
int main(int index)
{
    float mat1[16];

    float trans = Pos->translate;
    float rot = Pos->rotate;

    matrixLoadScale(mat1, 2.f, 2.f, 2.f);
    matrixTranslate(mat1, 0.f, 0.f, trans);
    matrixRotate(mat1, 90.f, 0.f, 0.f, 1.f);
    matrixRotate(mat1, rot, 1.f, 0.f, 0.f);
    vpLoadModelMatrix(mat1);

    // Draw the lighting effect in the strip and fill the Z buffer.
    drawSimpleMesh(NAMED_mesh);

    // Start of images.
    bindProgramStore(NAMED_PSImages);
    bindProgramFragment(NAMED_PFImages);
    bindProgramVertex(NAMED_PVImages);

    float focusPos = Pos->focus;
    int focusID = 0;
    int lastFocusID = loadI32(2, STATE_LAST_FOCUS);
    int imgCount = 13;

    if (trans > (-.3f)) {
        focusID = -1.0f - focusPos;
        if (focusID >= imgCount) {
            focusID = -1;
        }
    } else {
        focusID = -1;
    }

    /*
    if (focusID != lastFocusID) {
        if (lastFocusID >= 0) {
            uploadToTexture(con, env->tex[lastFocusID], 1);
        }
        if (focusID >= 0) {
            uploadToTexture(con, env->tex[focusID], 0);
        }
    }
    */
    lastFocus = focusID;

    int triangleOffsetsCount = Pos->triangleOffsetCount;

    int imgId = 0;
    for (imgId=1; imgId <= imgCount; imgId++) {
        float pos = focusPos + imgId + 0.4f;
        int offset = (int)floorf(pos * 2.f);
        pos = pos - 0.75f;

        offset = offset + triangleOffsetsCount / 2;
        if (!((offset < 0) || (offset >= triangleOffsetsCount))) {
            int start = offset -2;
            int end = offset + 2;

            if (start < 0) {
                start = 0;
            }
            if (end >= triangleOffsetsCount) {
                end = triangleOffsetsCount-1;
            }

            bindTexture(NAMED_PFImages, 0, loadI32(0, imgId - 1));
            matrixLoadTranslate(mat1, -pos - loadF(5, triangleOffsetsCount / 2), 0, 0);
            vpLoadTextureMatrix(mat1);
            drawSimpleMeshRange(NAMED_mesh, loadI32(4, start), (loadI32(4, end) - loadI32(4, start)));
        }
    }
    return 0;
}
void GoogleMapWidget::tileUpdated(const QString &id)
{
	boundTiles.insert(id, bindTexture(tileCache.getBitmap(id), GL_TEXTURE_2D, GL_RGBA, QGLContext::NoBindOption));

	update();
}
Example #13
0
void ATexture2D::loadFile(QString filename)
{
    initializeGLFunctions();
    m_fileName = filename;
    bindTexture();
}
void MGLES2Renderer::bindTexture(const QPixmap &pixmap, quint32 unit, const QString &uniformName)
{
    glActiveTexture(GL_TEXTURE0 + unit);
    bindTexture(d_ptr->m_glContext->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, QGLContext::PremultipliedAlphaBindOption), pixmap.size(), unit, uniformName);
    //bindTexture(d_ptr->m_glContext->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, QGLContext::NoBindOption), pixmap.size(), unit, uniformName);
}
Example #15
0
void GlutSlidingMainWindow::glDraw() {
    // drawing of the tab
	bindTexture();
	glPushMatrix();
	glTranslatef(x,y,0.0);
	glBegin(GL_QUADS);
	glTexCoord2f(0,0.0);
	glVertex2i(0,0);
	glTexCoord2f(0.3125,0.);
	glVertex2i(40,0);
	glTexCoord2f(0.3125,1);
	glVertex2i(40,128);
	glTexCoord2f(0,1);
	glVertex2i(0,128);
	glEnd();

	if (openingLevel) {
		glDisable(GL_LIGHTING);
		glDisable(GL_TEXTURE_2D);
		glColor4f(0.25,0.25,0.25,0.75);
		glBegin(GL_QUADS);
		//glTexCoord2f(0.3125,0.);
		glVertex2i(40,0);
		//glTexCoord2f(1.0,0.);
		glVertex2i(w,0);
		//glTexCoord2f(1.0,1.0);
		glVertex2i(w,h);
		//glTexCoord2f(0.3125,1.0);
		glVertex2i(40,h);
		glEnd();
		char str[256];
		uint64_t t = BaseSimulator::getScheduler()->now();
		if (t < 10*1000*1000) { //10sec
			sprintf(str,"Current time : %d:%d ms",int(t/1000),int((t%1000))); // ms
		} else {
			sprintf(str,"Current time : %d:%d s",int(t/1000000),int((t%1000000)/10000)); // s
		}
		glColor3f(1.0,1.0,0.0);
		drawString(42.0,h-20.0,str);
		glColor3f(1.0,1.0,1.0);
		if (selectedBlock) {
			sprintf(str,"Selected Block : %s",selectedBlock->getInfo().c_str());
			drawString(42.0,h-40.0,str);
			multimap<uint64_t,BlockDebugData*>::iterator it = traces.begin();
			GLfloat posy = h-65;
			stringstream line;
			int pos=slider->getPosition();
			int s,cs;
			while (it != traces.end() && posy>0) {
				if (((*it).second)->blockId==selectedBlock->blockId) {
					if (pos) {
						pos--;
					} else {
						((*it).second)->color.glColor();
						line.str("");
						s = (*it).first/1000;
						cs = ((*it).first%1000);
						line << "[" << s << ":" << cs << "] " << ((*it).second)->str;
						posy = drawString(42.0,posy,line.str().c_str());
					}
				}
				++it;
			}
		} else {
			sprintf(str, "Selected Block : None (use [Ctrl]+click)");
			drawString(42.0,h-40.0,str);
			multimap<uint64_t,BlockDebugData*>::iterator it = traces.begin();
			GLfloat posy = h-65;
			stringstream line;
			int pos=slider->getPosition();
			while (it != traces.end() && pos--) {
				it++;
			};

			int s,cs;
			while (it != traces.end() && posy>0) {
				((*it).second)->color.glColor();
				line.str("");
				s = (*it).first/1000;
				cs = ((*it).first%1000);
				line << "[" << s << ":" << cs << "] #" << ((*it).second)->blockId << ":" << ((*it).second)->str;
				posy = drawString(42.0,posy,line.str().c_str());
				++it;
			}
		}
	}
	glPopMatrix();
	GlutWindow::glDraw();
}
Example #16
0
/*******************************************************
* updateUnit()
*
* Description: Draws an individual unit.
*
* Inputs: Unit to be drawn.
*
* Outputs: none.
*
* Return: none.
*******************************************************/
void GLWidget::updateUnit(Unit myUnit)
{
    // Calculate the action and hit point bars as a percentage.
    float actionTime = (float)myUnit.actionTime / (float)100;
    float hitPoints = (float)myUnit.hitPoints / (float)myUnit.totalHitPoints;

    // Dynamically define the height and width of the sprite.
    float widthRatio = (float)myUnit.image.width() / (float)myUnit.image.height();
    int spriteHeight = cellHeight * 1.5 + 1;
    int spriteWidth = cellHeight * 1.5 * widthRatio;

    // Dynamically define the OpenGL location of the sprite.
    int bottomEdge = myUnit.vLocation * cellHeight + spriteHeight/6;
    int leftEdge = myUnit.hLocation * cellWidth + (cellWidth / 2) - (spriteWidth / 2);
    int rightEdge = leftEdge + spriteWidth;

    glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
    glBlendFunc( GL_DST_COLOR,GL_ZERO );

    glEnable(GL_TEXTURE_2D);
    GLuint textureMask = bindTexture( myUnit.mask_image, GL_TEXTURE_2D );

    // Draw the sprite facing right.
    if (myUnit.faceLeft)
    {
        glBegin (GL_QUADS);
        // Bottom left.
        glTexCoord2f (0.0, 0.0);
        glVertex3f (leftEdge, bottomEdge, 0.0);

        // Bottom right.
        glTexCoord2f (1.0, 0.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge, 0.0);

        // Top right.
        glTexCoord2f (1.0, 1.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge + spriteHeight, 0.0);

        // Top left.
        glTexCoord2f (0.0, 1.0);
        glVertex3f (leftEdge, bottomEdge + spriteHeight, 0.0);
        glEnd();
    }
    else
    {
        glBegin (GL_QUADS);
        // Bottom left.
        glTexCoord2f (1.0, 0.0);
        glVertex3f (leftEdge, bottomEdge, 0.0);

        // Bottom right.
        glTexCoord2f (0.0, 0.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge, 0.0);

        // Top right.
        glTexCoord2f (0.0, 1.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge + spriteHeight, 0.0);

        // Top left.
        glTexCoord2f (1.0, 1.0);
        glVertex3f (leftEdge, bottomEdge + spriteHeight, 0.0);
        glEnd ();
    }

    glBlendFunc(GL_ONE, GL_ONE);
    GLuint textureValue = bindTexture( myUnit.image, GL_TEXTURE_2D );

    // Draw the sprite facing left.
    if (myUnit.faceLeft)
    {
        glBegin (GL_QUADS);
        // Bottom left.
        glTexCoord2f (0.0, 0.0);
        glVertex3f (leftEdge, bottomEdge, 0.0);

        // Bottom right.
        glTexCoord2f (1.0, 0.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge, 0.0);

        // Top right.
        glTexCoord2f (1.0, 1.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge + spriteHeight, 0.0);

        // Top left.
        glTexCoord2f (0.0, 1.0);
        glVertex3f (leftEdge, bottomEdge + spriteHeight, 0.0);
        glEnd ();
    }
    else
    {
        glBegin(GL_QUADS);
        // Bottom left.
        glTexCoord2f (1.0, 0.0);
        glVertex3f (leftEdge, bottomEdge, 0.0);

        // Bottom right.
        glTexCoord2f (0.0, 0.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge, 0.0);

        // Top right.
        glTexCoord2f (0.0, 1.0);
        glVertex3f (leftEdge + spriteWidth, bottomEdge + spriteHeight, 0.0);

        // Top left.
        glTexCoord2f (1.0, 1.0);
        glVertex3f (leftEdge, bottomEdge + spriteHeight, 0.0);
        glEnd();
    }

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_TEXTURE_2D);

    // Free memory.
    glDeleteTextures( 1, &textureMask );
    glDeleteTextures( 1, &textureValue );

    // Show unit's health.
    glColor3f(0.3f, 0.3f, 0.3f);
    glBegin(GL_QUADS);
    glVertex3f( leftEdge - statusWidth, bottomEdge + cellHeight/2, 0.0f );
    glVertex3f( leftEdge, bottomEdge + cellHeight/2, 0.0f );
    glVertex3f( leftEdge,  bottomEdge, 0.0f );
    glVertex3f( leftEdge - statusWidth, bottomEdge, 0.0f );
    glEnd();
    glColor3f(0.0f, 0.6f, 0.0f);
    if (myUnit.team == AI_UNIT)
    {
        glColor3f(0.6f, 0.0f, 0.0f);
    }
    glBegin(GL_QUADS);
    glVertex3f( leftEdge - statusWidth, bottomEdge + cellHeight/2 * hitPoints, 0.0f );
    glVertex3f( leftEdge, bottomEdge + cellHeight/2 * hitPoints, 0.0f );
    glVertex3f( leftEdge,  bottomEdge, 0.0f );
    glVertex3f( leftEdge - statusWidth, bottomEdge, 0.0f );
    glEnd();

    // Show unit's action points.
    glColor3f(0.3f, 0.3f, 0.3f);
    glBegin(GL_QUADS);
    glVertex3f( rightEdge, bottomEdge + cellHeight/2, 0.0f );	// Top Left
    glVertex3f( rightEdge + statusWidth, bottomEdge + cellHeight/2, 0.0f );	//Top Right
    glVertex3f( rightEdge + statusWidth, bottomEdge, 0.0f );	// Bottom Right
    glVertex3f( rightEdge, bottomEdge, 0.0f );	// Bottom Left
    glEnd();
    glColor3f(0.0f, 0.0f, 0.6f);
    glBegin(GL_QUADS);
    glVertex3f( rightEdge, bottomEdge + cellHeight/2 * actionTime, 0.0f );	// Top Left
    glVertex3f( rightEdge + statusWidth, bottomEdge + cellHeight/2 * actionTime, 0.0f );	//Top Right
    glVertex3f( rightEdge + statusWidth, bottomEdge, 0.0f );	// Bottom Right
    glVertex3f( rightEdge, bottomEdge, 0.0f );	// Bottom Left
    glEnd();
}
Example #17
0
void GlutSlider::glDraw() {
	int byhy = buttonY+buttonHeight,
	    byhy_2=buttonY+buttonHeight/2;
	glPushMatrix();
	glTranslatef(x,y,0);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glColor3f(0.5,0.5,0.5);
	// free area inf
	glBegin(GL_QUADS);
	glVertex2i(0,10);
	glVertex2i(w,10);
	glVertex2i(w,buttonY);
	glVertex2i(0,buttonY);
	glEnd();
	// free area sup
	glBegin(GL_QUADS);
	glVertex2i(0,byhy);
	glVertex2i(w,byhy);
	glVertex2i(w,h-10);
	glVertex2i(0,h-10);
	glEnd();
	bindTexture();
	// button inf
	glBegin(GL_QUADS);
	glTexCoord2f(0,0);
	glVertex2i(0,0);
	glTexCoord2f(1,0);
	glVertex2i(w,0);
	glTexCoord2f(1,10.0/35.0);
	glVertex2i(w,10);
	glTexCoord2f(0,10.0/35.0);
	glVertex2i(0,10);
	glEnd();
	// button sup
	glBegin(GL_QUADS);
	glTexCoord2f(0,25.0/35.0);
	glVertex2i(0,h-10);
	glTexCoord2f(1,25.0/35.0);
	glVertex2i(w,h-10);
	glTexCoord2f(1,1);
	glVertex2i(w,h);
	glTexCoord2f(0,1);
	glVertex2i(0,h);
	glEnd();

	glBegin(GL_QUAD_STRIP);
	glTexCoord2f(0,11.0/35.0);
	glVertex2i(0,buttonY);
	glTexCoord2f(1,11.0/35.0);
	glVertex2i(w,buttonY);
	glTexCoord2f(0,12.0/35.0);
	glVertex2i(0,byhy_2-4);
	glTexCoord2f(1,12.0/35.0);
	glVertex2i(w,byhy_2-4);
	glTexCoord2f(0,23.0/35.0);
	glVertex2i(0,byhy_2+4);
	glTexCoord2f(1,23.0/35.0);
	glVertex2i(w,byhy_2+4);
	glTexCoord2f(0,24.0/35.0);
	glVertex2i(0,byhy);
	glTexCoord2f(1,24.0/35.0);
	glVertex2i(w,byhy);
	glTexCoord2f(0,25.0/35.0);
	glVertex2i(0,byhy);
	glTexCoord2f(1,25.0/35.0);
	glVertex2i(w,byhy);
	glEnd();
	glPopMatrix();
}
Example #18
0
/*******************************************************
* drawAttack()
*
* Description: Handles and draws the special effect for
* the attack function.
*
* Inputs: none
*
* Outputs: none
*
* Return: none
*******************************************************/
void GLWidget::drawAttack()
{
    QImage mask_image, image;

    mask_image.load("effects/mask_wisp.png");
    image.load("effects/wisp.png");

    // Dynamically define the height and width of the sprite.
    float widthRatio = (float)image.width() / (float)image.height();
    int spriteHeight = cellHeight * 1.5 + 1;
    int spriteWidth = cellHeight * 1.5 * widthRatio;

    // Dynamically define the OpenGL location of the sprite.
    int bottomEdge = attack_vLoc * cellHeight + spriteHeight/6;
    int leftEdge = attack_hLoc * cellWidth + (cellWidth / 2) - (spriteWidth / 2);

    glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
    glBlendFunc( GL_DST_COLOR,GL_ZERO );

    glEnable(GL_TEXTURE_2D);

    GLuint textureMask = bindTexture( mask_image, GL_TEXTURE_2D );

    glBegin (GL_QUADS);
    // Bottom left.
    glTexCoord2f (0.0, 0.0);
    glVertex3f (leftEdge, bottomEdge, 0.0);

    // Bottom right.
    glTexCoord2f (1.0, 0.0);
    glVertex3f (leftEdge + spriteWidth, bottomEdge, 0.0);

    // Top right.
    glTexCoord2f (1.0, 1.0);
    glVertex3f (leftEdge + spriteWidth, bottomEdge + spriteHeight, 0.0);

    // Top left.
    glTexCoord2f (0.0, 1.0);
    glVertex3f (leftEdge, bottomEdge + spriteHeight, 0.0);
    glEnd();

    glBlendFunc(GL_ONE, GL_ONE);
    GLuint textureValue = bindTexture( image, GL_TEXTURE_2D );

    glBegin (GL_QUADS);
    // Bottom left.
    glTexCoord2f (0.0, 0.0);
    glVertex3f (leftEdge, bottomEdge, 0.0);

    // Bottom right.
    glTexCoord2f (1.0, 0.0);
    glVertex3f (leftEdge + spriteWidth, bottomEdge, 0.0);

    // Top right.
    glTexCoord2f (1.0, 1.0);
    glVertex3f (leftEdge + spriteWidth, bottomEdge + spriteHeight, 0.0);

    // Top left.
    glTexCoord2f (0.0, 1.0);
    glVertex3f (leftEdge, bottomEdge + spriteHeight, 0.0);
    glEnd ();

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_TEXTURE_2D);

    // Free memory.
    glDeleteTextures( 1, &textureMask );
    glDeleteTextures( 1, &textureValue );
}
// 
//      updateRegistry
//
//      When attributes change which affect the shader compilation the
//      effectRegistry needs to be updated with the new values
//
void
OpenSubdivPtexShader::updateRegistry()
{
    // adaptive toggle
    if (_adaptiveDirty) {
        effectRegistry.setIsAdaptive(_adaptive);
        _adaptiveDirty = false;
    }

    // ptex color file
    if (_ptexColorDirty) {
        bool ptexColorValid = bindPtexTexture(_colorFile, &_ptexColor, CLR_TEXTURE_UNIT);
        effectRegistry.setPtexColorValid(ptexColorValid);
        _ptexColorDirty = false;
    }

    // ptex displacement file
    if (_ptexDisplacementDirty) {
        bool ptexDisplacementValid = bindPtexTexture(_displacementFile, &_ptexDisplacement, DISP_TEXTURE_UNIT);
        effectRegistry.setPtexDisplacementValid(ptexDisplacementValid);
        _ptexDisplacementDirty = false;
    }

    // ptex occlusion file
    if (_ptexOcclusionDirty) {
        bool ptexOcclusionValid = bindPtexTexture(_occlusionFile, &_ptexOcclusion, OCC_TEXTURE_UNIT);
        effectRegistry.setPtexOcclusionValid(ptexOcclusionValid);
        _ptexOcclusionDirty = false;
    }


    MHWRender::MRenderer *theRenderer = MHWRender::MRenderer::theRenderer();
    _theTextureManager = theRenderer->getTextureManager();

    // diffuse environment map file
    if (_diffEnvMapDirty) {
        GLuint diffEnvMapId = bindTexture( _diffEnvMapFile, DIFF_TEXTURE_UNIT );
        effectRegistry.setDiffuseEnvironmentId(diffEnvMapId);
        _diffEnvMapDirty = false;
    }

    // specular environment map file
    if (_specEnvMapDirty) {
        GLuint specEnvMapId = bindTexture( _specEnvMapFile, ENV_TEXTURE_UNIT );
        effectRegistry.setSpecularEnvironmentId(specEnvMapId);
        _specEnvMapDirty = false;
    }

    // shader source
    if (_shaderSourceDirty) {
        if ( _shaderSource.empty() ) {
            if ( effectRegistry.getShaderSource() != defaultShaderSource ) {
                effectRegistry.setShaderSource(defaultShaderSource);
            }
        } else {
            if ( effectRegistry.getShaderSource() != _shaderSource ) {
                effectRegistry.setShaderSource(_shaderSource);
            }
        }
        _shaderSourceDirty = false;
    }
}
Example #20
0
void Visualizer::initializeGL()
{
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    qglClearColor(QColor(Qt::black));

    QFile file("../../../../RubicCubeSolver/objects/box3.obj");
    int x;
    for(int i=0;i<27;i++)
        x = ObjectLoader(&file);

    //Bind Fragment and Vertex Shader for the Cube
    QGLShaderProgram* tmpShaderProg = new QGLShaderProgram;
    tmpShaderProg->addShaderFromSourceFile(QGLShader::Vertex, "../../../../RubicCubeSolver/lightingVertexShader2.vs");
    tmpShaderProg->addShaderFromSourceFile(QGLShader::Fragment, "../../../../RubicCubeSolver/lightingFragmentShader2.fs");
    tmpShaderProg->link();

    lightingShaderProgram.addShaderFromSourceFile(QGLShader::Vertex, "../../../../RubicCubeSolver/lightingVertexShader.vs");
    lightingShaderProgram.addShaderFromSourceFile(QGLShader::Fragment, "../../../../RubicCubeSolver/lightingFragmentShader.fs");
    lightingShaderProgram.link();

    cubeVertices << QVector3D(-0.5, -0.5,  0.5) << QVector3D( 0.5, -0.5,  0.5) << QVector3D( 0.5,  0.5,  0.5) << QVector3D(-0.5,  0.5,  0.5) // Front
                 << QVector3D( 0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5,  0.5, -0.5) << QVector3D( 0.5,  0.5, -0.5) // Back
                 << QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5,  0.5) << QVector3D(-0.5,  0.5,  0.5) << QVector3D(-0.5,  0.5, -0.5) // Left
                 << QVector3D( 0.5, -0.5,  0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5,  0.5, -0.5) << QVector3D( 0.5,  0.5,  0.5) // Right
                 << QVector3D(-0.5,  0.5,  0.5) << QVector3D( 0.5,  0.5,  0.5) << QVector3D( 0.5,  0.5, -0.5) << QVector3D(-0.5,  0.5, -0.5) // Top
                 << QVector3D(-0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5,  0.5) << QVector3D(-0.5, -0.5,  0.5);// Bottom

    cubeTextureCoordinates << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) << QVector2D(0, 1) // Front
                           << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) << QVector2D(0, 1) // Front
                           << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) << QVector2D(0, 1) // Front
                           << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) << QVector2D(0, 1) // Front
                           << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) << QVector2D(0, 1) // Front
                           << QVector2D(0, 0) << QVector2D(1, 0) << QVector2D(1, 1) << QVector2D(0, 1);// Front

    cubeNormals << QVector3D( 0,  0,  1) << QVector3D( 0,  0,  1) << QVector3D( 0,  0,  1) << QVector3D( 0,  0,  1) // Front
                << QVector3D( 0,  0, -1) << QVector3D( 0,  0, -1) << QVector3D( 0,  0, -1) << QVector3D( 0,  0, -1) // Back
                << QVector3D(-1,  0,  0) << QVector3D(-1,  0,  0) << QVector3D(-1,  0,  0) << QVector3D(-1,  0,  0) // Left
                << QVector3D( 1,  0,  0) << QVector3D( 1,  0,  0) << QVector3D( 1,  0,  0) << QVector3D( 1,  0,  0) // Right
                << QVector3D( 0,  1,  0) << QVector3D( 0,  1,  0) << QVector3D( 0,  1,  0) << QVector3D( 0,  1,  0) // Top
                << QVector3D( 0, -1,  0) << QVector3D( 0, -1,  0) << QVector3D( 0, -1,  0) << QVector3D( 0, -1,  0); // Bottom

    cubeTexture = bindTexture(QPixmap("../../../../RubicCubeSolver/texture.png"));

//    QGLBuffer* tmpBuffer = WriteBufferData(cubeVertices,cubeNormals,cubeTextureCoordinates);
//    m_pBufferList.append(new m_pBufferShaderList(2, cubeVertices.size(), tmpBuffer, tmpShaderProg));
    for(int i=0;i<27;i++)
    {
    m_pBufferList[i]->shaderProgram = tmpShaderProg;
    m_pBufferList[i]->variable1 = "vertex";
    m_pBufferList[i]->variable2 = "normal";
    m_pBufferList[i]->variable3 = "color";
    m_pBufferList[i]->numVaiables = 3;
    }

    //Bind Fragment and Vertex shadet for the Rotating Spotlight

    coloringShaderProgram.addShaderFromSourceFile(QGLShader::Vertex, "../../../../RubicCubeSolver/coloringVertexShader.vs");
    coloringShaderProgram.addShaderFromSourceFile(QGLShader::Fragment, "../../../../RubicCubeSolver/coloringFragmentShader.fs");
    coloringShaderProgram.link();

    spotlightVertices << QVector3D(   0,    1,    0) << QVector3D(-0.5,    0,  0.5) << QVector3D( 0.5,    0,  0.5) // Front
                      << QVector3D(   0,    1,    0) << QVector3D( 0.5,    0, -0.5) << QVector3D(-0.5,    0, -0.5) // Back
                      << QVector3D(   0,    1,    0) << QVector3D(-0.5,    0, -0.5) << QVector3D(-0.5,    0,  0.5) // Left
                      << QVector3D(   0,    1,    0) << QVector3D( 0.5,    0,  0.5) << QVector3D( 0.5,    0, -0.5) // Right
                      << QVector3D(-0.5,    0, -0.5) << QVector3D( 0.5,    0, -0.5) << QVector3D( 0.5,    0,  0.5) // Bottom
                      << QVector3D( 0.5,    0,  0.5) << QVector3D(-0.5,    0,  0.5) << QVector3D(-0.5,    0, -0.5);
    spotlightColors << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Front
                    << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Back
                    << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Left
                    << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) << QVector3D(0.2, 0.2, 0.2) // Right
                    << QVector3D(  1,   1,   1) << QVector3D(  1,   1,   1) << QVector3D(  1,   1,   1) // Bottom
                    << QVector3D(  1,   1,   1) << QVector3D(  1,   1,   1) << QVector3D(  1,   1,   1);

    //Bind Fragment and Vertex shadet for the non-Rotating left-Spotlight

    leftlightShaderProgram.addShaderFromSourceFile(QGLShader::Vertex, "../../../../RubicCubeSolver/leftlightVertexShader.vs");
    leftlightShaderProgram.addShaderFromSourceFile(QGLShader::Fragment, "../../../../RubicCubeSolver/leftlightFragmentShader.fs");
    leftlightShaderProgram.link();


    //Writing Buffer Vertices, Normals and textures for the Cube

    numCubeVertices = 24;
    cubeBuffer.create();
    cubeBuffer.bind();
    cubeBuffer.allocate(numCubeVertices * (3+3+2) * sizeof (GLfloat));
    int offset = 0;
    cubeBuffer.write(offset, cubeVertices.constData(), numCubeVertices * 3 * sizeof (GLfloat));
    offset += numCubeVertices * 3 * sizeof (GLfloat);
    cubeBuffer.write(offset, cubeNormals.constData(), numCubeVertices * 3 * sizeof (GLfloat));
    offset += numCubeVertices * 3 * sizeof (GLfloat);
    cubeBuffer.write(offset, cubeTextureCoordinates.constData(), numCubeVertices * 2 *sizeof (GLfloat));
    cubeBuffer.release();

    //Writting Buffer Vertices and Colors for the Rotating spotlight

    numSpotlightVertices = 18;
    spotlightBuffer.create();
    spotlightBuffer.bind();
    spotlightBuffer.allocate(numSpotlightVertices * (3+3) * sizeof (GLfloat));
    offset = 0;
    spotlightBuffer.write(offset, spotlightVertices.constData(), numSpotlightVertices * 3 * sizeof (GLfloat));
    offset += numSpotlightVertices * 3 * sizeof (GLfloat);
    spotlightBuffer.write(offset, spotlightColors.constData(), numSpotlightVertices * 3 * sizeof (GLfloat));
    offset += numSpotlightVertices * 3 * sizeof (GLfloat);
    spotlightBuffer.release();
}
Example #21
0
Sprite::Sprite(TexturePtr texture) : Sprite()
{
	bindTexture(texture);
}
Example #22
0
void QSGVideoMaterial_YUV::bind()
{
    QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
    QMutexLocker lock(&m_frameMutex);
    if (m_frame.isValid()) {
        if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
            int fw = m_frame.width();
            int fh = m_frame.height();

            // Frame has changed size, recreate textures...
            if (m_textureSize != m_frame.size()) {
                if (!m_textureSize.isEmpty())
                    functions->glDeleteTextures(m_planeCount, m_textureIds);
                functions->glGenTextures(m_planeCount, m_textureIds);
                m_textureSize = m_frame.size();
            }

            GLint previousAlignment;
            functions->glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousAlignment);
            functions->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            if (m_format.pixelFormat() == QVideoFrame::Format_NV12
                    || m_format.pixelFormat() == QVideoFrame::Format_NV21) {
                const int y = 0;
                const int uv = 1;

                m_planeWidth[0] = m_planeWidth[1] = qreal(fw) / m_frame.bytesPerLine(y);

                functions->glActiveTexture(GL_TEXTURE1);
                bindTexture(m_textureIds[1], m_frame.bytesPerLine(uv) / 2, fh / 2, m_frame.bits(uv), GL_LUMINANCE_ALPHA);
                functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
                bindTexture(m_textureIds[0], m_frame.bytesPerLine(y), fh, m_frame.bits(y), GL_LUMINANCE);

            } else { // YUV420P || YV12
                const int y = 0;
                const int u = m_frame.pixelFormat() == QVideoFrame::Format_YUV420P ? 1 : 2;
                const int v = m_frame.pixelFormat() == QVideoFrame::Format_YUV420P ? 2 : 1;

                m_planeWidth[0] = qreal(fw) / m_frame.bytesPerLine(y);
                m_planeWidth[1] = m_planeWidth[2] = qreal(fw) / (2 * m_frame.bytesPerLine(u));

                functions->glActiveTexture(GL_TEXTURE1);
                bindTexture(m_textureIds[1], m_frame.bytesPerLine(u), fh / 2, m_frame.bits(u), GL_LUMINANCE);
                functions->glActiveTexture(GL_TEXTURE2);
                bindTexture(m_textureIds[2], m_frame.bytesPerLine(v), fh / 2, m_frame.bits(v), GL_LUMINANCE);
                functions->glActiveTexture(GL_TEXTURE0); // Finish with 0 as default texture unit
                bindTexture(m_textureIds[0], m_frame.bytesPerLine(y), fh, m_frame.bits(y), GL_LUMINANCE);
            }

            functions->glPixelStorei(GL_UNPACK_ALIGNMENT, previousAlignment);
            m_frame.unmap();
        }

        m_frame = QVideoFrame();
    } else {
        // Go backwards to finish with GL_TEXTURE0
        for (int i = m_planeCount - 1; i >= 0; --i) {
            functions->glActiveTexture(GL_TEXTURE0 + i);
            functions->glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
        }
    }
}
Example #23
0
void bindTexture(const VolumeInport& inport, const TextureUnit& texUnit) {
    bindTexture(*inport.getData(), texUnit);
}
gl::Error StateManagerGL::setGenericDrawState(const gl::Data &data)
{
    const gl::State &state = *data.state;

    // If the context has changed, pause the previous context's transform feedback and queries
    if (data.context != mPrevDrawContext)
    {
        if (mPrevDrawTransformFeedback != nullptr)
        {
            mPrevDrawTransformFeedback->syncPausedState(true);
        }

        for (QueryGL *prevQuery : mPrevDrawQueries)
        {
            prevQuery->pause();
        }
    }
    mPrevDrawTransformFeedback = nullptr;
    mPrevDrawQueries.clear();

    mPrevDrawContext = data.context;

    // Sync the current program state
    const gl::Program *program = state.getProgram();
    const ProgramGL *programGL = GetImplAs<ProgramGL>(program);
    useProgram(programGL->getProgramID());

    for (size_t uniformBlockIndex = 0; uniformBlockIndex < program->getActiveUniformBlockCount();
         uniformBlockIndex++)
    {
        GLuint binding = program->getUniformBlockBinding(static_cast<GLuint>(uniformBlockIndex));
        const OffsetBindingPointer<gl::Buffer> &uniformBuffer =
            data.state->getIndexedUniformBuffer(binding);

        if (uniformBuffer.get() != nullptr)
        {
            BufferGL *bufferGL = GetImplAs<BufferGL>(uniformBuffer.get());

            if (uniformBuffer.getSize() == 0)
            {
                bindBufferBase(GL_UNIFORM_BUFFER, binding, bufferGL->getBufferID());
            }
            else
            {
                bindBufferRange(GL_UNIFORM_BUFFER, binding, bufferGL->getBufferID(),
                                uniformBuffer.getOffset(), uniformBuffer.getSize());
            }
        }
    }

    const std::vector<SamplerBindingGL> &appliedSamplerUniforms = programGL->getAppliedSamplerUniforms();
    for (const SamplerBindingGL &samplerUniform : appliedSamplerUniforms)
    {
        GLenum textureType = samplerUniform.textureType;
        for (GLuint textureUnitIndex : samplerUniform.boundTextureUnits)
        {
            const gl::Texture *texture = state.getSamplerTexture(textureUnitIndex, textureType);
            if (texture != nullptr)
            {
                const TextureGL *textureGL = GetImplAs<TextureGL>(texture);

                if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID())
                {
                    activeTexture(textureUnitIndex);
                    bindTexture(textureType, textureGL->getTextureID());
                }

                textureGL->syncState(textureUnitIndex, texture->getTextureState());
            }
            else
            {
                if (mTextures[textureType][textureUnitIndex] != 0)
                {
                    activeTexture(textureUnitIndex);
                    bindTexture(textureType, 0);
                }
            }

            const gl::Sampler *sampler = state.getSampler(textureUnitIndex);
            if (sampler != nullptr)
            {
                const SamplerGL *samplerGL = GetImplAs<SamplerGL>(sampler);
                samplerGL->syncState(sampler->getSamplerState());
                bindSampler(textureUnitIndex, samplerGL->getSamplerID());
            }
            else
            {
                bindSampler(textureUnitIndex, 0);
            }
        }
    }

    const gl::Framebuffer *framebuffer = state.getDrawFramebuffer();
    const FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(framebuffer);
    bindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferGL->getFramebufferID());
    framebufferGL->syncDrawState();

    // Seamless cubemaps are required for ES3 and higher contexts.
    setTextureCubemapSeamlessEnabled(data.clientVersion >= 3);

    // Set the current transform feedback state
    gl::TransformFeedback *transformFeedback = state.getCurrentTransformFeedback();
    if (transformFeedback)
    {
        TransformFeedbackGL *transformFeedbackGL =
            GetImplAs<TransformFeedbackGL>(transformFeedback);
        bindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedbackGL->getTransformFeedbackID());
        transformFeedbackGL->syncActiveState(transformFeedback->isActive(),
                                             transformFeedback->getPrimitiveMode());
        transformFeedbackGL->syncPausedState(transformFeedback->isPaused());
        mPrevDrawTransformFeedback = transformFeedbackGL;
    }
    else
    {
        bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
        mPrevDrawTransformFeedback = nullptr;
    }

    // Set the current query state
    for (GLenum queryType : QueryTypes)
    {
        gl::Query *query = state.getActiveQuery(queryType);
        if (query != nullptr)
        {
            QueryGL *queryGL = GetImplAs<QueryGL>(query);
            queryGL->resume();

            mPrevDrawQueries.insert(queryGL);
        }
    }

    return gl::Error(GL_NO_ERROR);
}
void setupGpu()
{
    int err;


    /////////////////////////////////////////////////////////////
    //Compile Source

    //Read file
    FILE* kernelFile = fopen("GpuTemporalDataMining.cl", "r");
    fseek(kernelFile, 0, SEEK_END);
    size_t kernelLength = (size_t) ftell(kernelFile);
    char* kernelSource = (char *) malloc(sizeof(char)*(kernelLength+1));
    rewind(kernelFile);
    int read = fread((void *) kernelSource, kernelLength, 1, kernelFile);
    fclose(kernelFile);
    kernelSource[kernelLength] = 0;
     // Create the compute program from the source buffer
    program = clCreateProgramWithSource(context, 1, (const char **) &kernelSource, NULL, &err);
    CHKERR(err, "Failed to create a compute program!");

	printf("MaxImageWidth: %d, MaxImageHeight: %d\n",(int)MaxImageWidth, (int)MaxImageHeight);
    // Build the program executable
    char options[200];
    snprintf(options, 200, "-I . -D IMAGE_MAX_WIDTH=%lu -D IMAGE_MAX_HEIGHT=%lu", (unsigned long)MaxImageWidth, (unsigned long)MaxImageHeight);
    err = clBuildProgram(program, 1, &device_id, options, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        char *log;
        size_t logLen;
        int err2;
        err2 = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &logLen);
        log = (char *) malloc(sizeof(char)*logLen);
        err2 = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, logLen, (void *) log, NULL);
        fprintf(stderr, "CL Error %d: Failed to build program! Log:\n%s", err, log);
        free(log);
        exit(1);
    }
    CHKERR(err, "Failed to build program!");

    free(kernelSource);

    kernel_countCandidates = clCreateKernel(program, "countCandidates", &err);
    CHKERR(err, "Failed to create a compute kernel!");

    kernel_countCandidatesStatic = clCreateKernel(program, "countCandidatesStatic", &err);
    CHKERR(err, "Failed to create a compute kernel!");

    kernel_countCandidatesMapMerge = clCreateKernel(program, "countCandidatesMapMerge", &err);
    CHKERR(err, "Failed to create a compute kernel!");

    kernel_countCandidatesMapMergeStatic = clCreateKernel(program, "countCandidatesMapMergeStatic", &err);
    CHKERR(err, "Failed to create a compute kernel!");

    kernel_analyzeSupport = clCreateKernel(program, "analyzeSupport", &err);
    CHKERR(err, "Failed to create a compute kernel!");

    kernel_generateEpisodeCandidatesKernel = clCreateKernel(program, "generateEpisodeCandidatesKernel", &err);
    CHKERR(err, "Failed to create a compute kernel!");
    /////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////
    //Setup memory


    d_events = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, roundup(padEventSize) * sizeof(UBYTE), (void*)h_events, &err);
    CHKERR(err, "Failed to allocate device memory!");
    bindTexture(0, &eventTex, d_events, roundup(padEventSize) * sizeof(UBYTE), CL_UNSIGNED_INT8);

	free( h_events );

	d_times = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, roundup(padEventSize) * sizeof(float), (void*)h_times, &err);
    CHKERR(err, "Failed to allocate device memory!");
    bindTexture(0, &timeTex, d_times, roundup(padEventSize), CL_FLOAT);
	free( h_times );


    d_episodeCandidates = clCreateBuffer(context, CL_MEM_READ_WRITE, maxCandidates * sizeof(UBYTE), NULL, &err);
    CHKERR(err, "Failed to allocate device memory!");
    d_episodeCandidatesBuffer = clCreateBuffer(context, CL_MEM_READ_WRITE, maxCandidates * sizeof(UBYTE), NULL, &err);
    CHKERR(err, "Failed to allocate device memory!");

    h_episodeCandidates = (UBYTE*)malloc( maxCandidates*sizeof(UBYTE) );
	h_episodeCandidatesBuffer = (UBYTE*)malloc( maxCandidates*sizeof(UBYTE) );


	d_episodeIntervals = clCreateBuffer(context, CL_MEM_READ_WRITE, maxIntervals * sizeof(float), NULL, &err);
    CHKERR(err, "Failed to allocate device memory!");
	d_episodeIntervalsBuffer = clCreateBuffer(context, CL_MEM_READ_WRITE, maxIntervals * sizeof(float), NULL, &err);
    CHKERR(err, "Failed to allocate device memory!");

	h_episodeIntervals = (float*)malloc( maxIntervals*sizeof(float) );
	h_episodeIntervalsBuffer = (float*)malloc( maxIntervals*sizeof(float) );

    // Results
	h_episodeSupport = (float*)malloc( maxCandidates*sizeof(float) );
	d_episodeSupport = clCreateBuffer(context, CL_MEM_READ_WRITE, maxCandidates * sizeof(float), NULL, &err);
    CHKERR(err, "Failed to allocate device memory!");

	//h_mapRecords = (float*)malloc( 3 * numSections * maxLevel * maxCandidates * sizeof(float) );
	//CUDA_SAFE_CALL( cudaMalloc( (void**)&d_mapRecords, 3 * numSections * maxLevel * maxCandidates * sizeof(float)) );

    /////////////////////////////////////////////////////////////
}
Example #26
0
gl::Error StateManagerGL::setGenericDrawState(const gl::Data &data)
{
    const gl::State &state = *data.state;
    const gl::Caps &caps = *data.caps;

    const gl::Program *program = state.getProgram();
    const ProgramGL *programGL = GetImplAs<ProgramGL>(program);
    useProgram(programGL->getProgramID());

    // TODO: Only apply textures referenced by the program.
    for (auto textureTypeIter = mTextures.begin(); textureTypeIter != mTextures.end(); textureTypeIter++)
    {
        GLenum textureType = textureTypeIter->first;

        // Determine if this texture type can exist in the source context
        bool validTextureType = (textureType == GL_TEXTURE_2D || textureType == GL_TEXTURE_CUBE_MAP ||
                                 (textureType == GL_TEXTURE_2D_ARRAY && data.clientVersion >= 3) ||
                                 (textureType == GL_TEXTURE_3D && data.clientVersion >= 3));

        const std::vector<GLuint> &textureVector = textureTypeIter->second;
        for (size_t textureUnitIndex = 0; textureUnitIndex < textureVector.size(); textureUnitIndex++)
        {
            const gl::Texture *texture = nullptr;

            bool validTextureUnit = textureUnitIndex < caps.maxCombinedTextureImageUnits;
            if (validTextureType && validTextureUnit)
            {
                texture = state.getSamplerTexture(textureUnitIndex, textureType);
            }

            if (texture != nullptr)
            {
                const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
                textureGL->syncSamplerState(texture->getSamplerState());

                if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID())
                {
                    activeTexture(textureUnitIndex);
                    bindTexture(textureType, textureGL->getTextureID());
                }

                // TODO: apply sampler object if one is bound
            }
            else
            {
                if (mTextures[textureType][textureUnitIndex] != 0)
                {
                    activeTexture(textureUnitIndex);
                    bindTexture(textureType, 0);
                }
            }
        }
    }

    const gl::Framebuffer *framebuffer = state.getDrawFramebuffer();
    const FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(framebuffer);
    bindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferGL->getFramebufferID());

    setScissor(state.getScissor());
    setViewport(state.getViewport());

    const gl::BlendState &blendState = state.getBlendState();
    setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha);

    const gl::DepthStencilState &depthStencilState = state.getDepthStencilState();
    setDepthMask(depthStencilState.depthMask);
    setStencilMask(depthStencilState.stencilMask);

    return gl::Error(GL_NO_ERROR);
}
Example #27
0
Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage,
                                 int width, int height)
{
    if (!tmpImage)
        return nullptr;

    BLOCK_START("OpenGLImageHelper::glLoad")
    // Flush current error flag.
    graphicsManager.getLastError();

    if (!width)
        width = tmpImage->w;
    if (!height)
        height = tmpImage->h;

    SDL_Surface *oldImage = tmpImage;
    tmpImage = convertSurface(tmpImage, width, height);

    const int realWidth = tmpImage->w;
    const int realHeight = tmpImage->h;

    const GLuint texture = getNewTexture();
    bindTexture(texture);

    if (SDL_MUSTLOCK(tmpImage))
        SDL_LockSurface(tmpImage);

    if (mUseOpenGL != RENDER_MODERN_OPENGL && mUseOpenGL != RENDER_GLES_OPENGL)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    if (!mUseTextureSampler)
    {
        if (mBlur)
        {
            glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        }
        else
        {
            glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        }
    }
#ifndef ANDROID
    glTexParameteri(mTextureType, GL_TEXTURE_MAX_LEVEL, 0);
#endif

    glTexImage2D(mTextureType, 0, mInternalTextureType,
        tmpImage->w, tmpImage->h,
        0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);

#ifdef DEBUG_OPENGL
//  disabled for now, because debugger can't show it
//    if (isGLNotNull(mglLabelObject))
//    {
//        const char *const text = "image text";
//        mglLabelObject(GL_TEXTURE, texture, strlen(text), text);
//    }
#endif

/*
    GLint compressed;
    glGetTexLevelParameteriv(mTextureType, 0,
        GL_TEXTURE_COMPRESSED_ARB, &compressed);
    if (compressed)
        logger->log("image compressed");
    else
        logger->log("image not compressed");
*/

#ifdef DEBUG_OPENGL_LEAKS
    textures_count ++;
#endif

    if (SDL_MUSTLOCK(tmpImage))
        SDL_UnlockSurface(tmpImage);

    if (oldImage != tmpImage)
        MSDL_FreeSurface(tmpImage);

    GLenum error = graphicsManager.getLastError();
    if (error)
    {
        std::string errmsg = GraphicsManager::errorToString(error);
        logger->log("Error: Image GL import failed: %s (%u)",
            errmsg.c_str(), error);
//        return nullptr;
    }

    BLOCK_END("OpenGLImageHelper::glLoad")
    return new Image(texture, width, height, realWidth, realHeight);
}
void MyGLWidget::paintEvent(QPaintEvent *)
{
    // 在当前窗口中进行OpenGL的绘制
    makeCurrent();
    // 将模型视图矩阵压入堆栈
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    // 以下是以前initializeGL()函数中的全部内容
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
    glClearDepth(1.0);
    glEnable(GL_DEPTH_TEST);

    textures[0] = bindTexture(QPixmap("../myOpenGL/side1.png"));
    textures[1] = bindTexture(QPixmap("../myOpenGL/side2.png"));
    textures[2] = bindTexture(QPixmap("../myOpenGL/side3.png"));
    glEnable(GL_TEXTURE_2D);

    // 该函数中是以前resizeGL()函数中的全部内容
    setupViewport(width(), height());

    // 以下是以前paintGL()函数中的全部内容
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glTranslatef(0.0, 0.0, translate);
    glRotatef(xRot, 1.0, 0.0, 0.0);
    glRotatef(yRot, 0.0, 1.0, 0.0);
    glRotatef(zRot, 0.0, 0.0, 1.0);

    glBindTexture(GL_TEXTURE_2D, textures[2]);
    glBegin(GL_QUADS);
    glTexCoord2f(1.0, 0.0);
    glVertex3f(1.0, 1.0, 1.0);
    glTexCoord2f(1.0, 1.0);
    glVertex3f(1.0, 1.0, -1.0);
    glTexCoord2f(0.0, 1.0);
    glVertex3f(-1.0, 1.0, -1.0);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(-1.0, 1.0, 1.0);
    glEnd();
    glBindTexture(GL_TEXTURE_2D, textures[1]);
    glBegin(GL_QUADS);
    glTexCoord2f(1.0, 0.0);
    glVertex3f(1.0, -1.0, 1.0);
    glTexCoord2f(1.0, 1.0);
    glVertex3f(1.0, -1.0, -1.0);
    glTexCoord2f(0.0, 1.0);
    glVertex3f(-1.0, -1.0, -1.0);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(-1.0, -1.0, 1.0);
    glEnd();
    glBindTexture(GL_TEXTURE_2D, textures[0]);
    glBegin(GL_QUADS);
    glTexCoord2f(1.0, 1.0);
    glVertex3f(1.0, 1.0, 1.0);
    glTexCoord2f(0.0, 1.0);
    glVertex3f(-1.0, 1.0, 1.0);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(-1.0, -1.0, 1.0);
    glTexCoord2f(1.0, 0.0);
    glVertex3f(1.0, -1.0, 1.0);
    glEnd();

    // 关闭启用的功能并弹出模型视图矩阵
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    // 下面是2D绘图的内容
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(Qt::red);
    painter.drawRect(0, 0, 100, 100);
    painter.end();
}
Example #29
0
void Quiddiards::drawTable(){
	static GLfloat x1 = table.getRugLen() / 2,
		y1 = table.getRugWid() / 2,
		z1 = table.getRugHgt(),
		x2 = table.getDamLen() / 2,
		y2 = table.getDamWid() / 2,
		z2 = table.getDamHgt(),
		z3 = table.getBtmHgt();
	static GLfloat pTable[14 * 4 * 3] = {
		//desktop
		x1, y1, z1, -x1, y1, z1, -x1, -y1, z1, x1, -y1, z1,
		//bottom
		x2, y2, z3, x2, -y2, z3, -x2, -y2, z3, -x2, y2, z3,
		//front inner face
		x1, -y1, z2, x1, y1, z2, x1, y1, z1, x1, -y1, z1,
		//front upper face
		x1, y2, z2, x1, -y2, z2, x2, -y2, z2, x2, y2, z2,
		//front outer face
		x2, y2, z2, x2, -y2, z2, x2, -y2, z3, x2, y2, z3,
		//right inner face
		x1, y1, z2, -x1, y1, z2, -x1, y1, z1, x1, y1, z1,
		//right upper face
		x2, y2, z2, -x2, y2, z2, -x2, y1, z2, x2, y1, z2,
		//right outer face
		-x2, y2, z2, x2, y2, z2, x2, y2, z3, -x2, y2, z3,
		//back inner face
		-x1, y1, z2, -x1, -y1, z2, -x1, -y1, z1, -x1, y1, z1,
		//back upper face
		-x1, -y2, z2, -x1, y2, z2, -x2, y2, z2, -x2, -y2, z2,
		//back outer face
		-x2, -y2, z2, -x2, y2, z2, -x2, y2, z3, -x2, -y2, z3,
		//left inner face
		-x1, -y1, z2, x1, -y1, z2, x1, -y1, z1, -x1, -y1, z1,
		//left upper face
		-x2, -y2, z2, x2, -y2, z2, x2, -y1, z2, -x2, -y1, z2,
		//left outer face
		x2, -y2, z2, -x2, -y2, z2, -x2, -y2, z3, x2, -y2, z3
	};
	static GLfloat pLegs[4 * 3] = {
		//leg centers
		x1, y1, 0, -x1, y1, 0, -x1, -y1, 0, x1, -y1, 0
	};
	static GLfloat pHoles[6 * 3] = {
		//hole centers
		x1 - 0.01, y1 - 0.01, z1 + 0.01,
		x1 - 0.01, -y1 + 0.01, z1 + 0.01,
		-x1 + 0.01, -y1 + 0.01, z1 + 0.01,
		-x1 + 0.01, y1 - 0.01, z1 + 0.01,
		0, y1 - 0.01, z1 + 0.01,
		0, -y1 + 0.01, z1 + 0.01
	};

	static GLfloat pTableTex[14 * 4 * 2] = {
		8, 0, 8, 8, 0, 8, 0, 0,
		8, 0, 8, 8, 0, 8, 0, 0,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1,
		0, 0, 4, 0, 4, 1, 0, 1
	};
	glPushMatrix();

	//draw table
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, pTable);
	glTexCoordPointer(2, GL_FLOAT, 0, pTableTex);
	//rug
	//glColor3ub(0x0, 0x5f, 0x0);
	bindTexture("rug.jpg");
	glDrawArrays(GL_QUADS, 0, 4);
	releaseTexture();
	//dam
	//glColor3ub(0x7f, 0x4f, 0x0);
	bindTexture("dam.jpg");
	glDrawArrays(GL_QUADS, 4, 13 * 4);
	releaseTexture();
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	//draw legs
	//glColor3ub(0x7f, 0x3f, 0x0);
	bindTexture("leg.jpg");
	for (int i = 0; i < 4; i++){
		glPushMatrix();
		glTranslatef(pLegs[3 * i], pLegs[3 * i + 1], pLegs[3 * i + 2]);
		gluCylinder(quad, table.getLegRad(), table.getLegRad(), table.getLegHgt(), 12, 6);
		glPopMatrix();
	}
	releaseTexture();

	// draw holes
	//glDisable(GL_CULL_FACE);
	//glColor3ub(0x0, 0x0, 0x0);
	//for (int i = 0; i < 6; i++){
	//	glPushMatrix();
	//	glTranslatef(pHoles[3 * i], pHoles[3 * i + 1], pHoles[3 * i + 2]);
	//	gluDisk(quad, 0, table.getHoleRad(), 12, 1);
	//	glRotatef(90, 1, 0, 0);
	//	gluDisk(quad, 0, table.getHoleRad(), 12, 1);
	//	if (i < 4){
	//		glRotatef(90, 0, 1, 0);
	//		gluDisk(quad, 0, table.getHoleRad(), 12, 1);
	//	}
	//	glPopMatrix();
	//}
	//glEnable(GL_CULL_FACE);

	glPopMatrix();
}
Example #30
0
void
bindTexture(TextureUnitId aTextureUnit, TextureTarget aTextureTarget, TextureId aTexture)
{
	activeTexture(aTextureUnit);
	bindTexture(aTextureTarget, aTexture);
}