Example #1
0
void setPixel( float x, float y, GLubyte rgb[]) {
	// Set the raster position for pixel
	glWindowPos2f( x, y );

	// Set the color for the pixel
	glDrawPixels(1, 1, GL_RGB, GL_UNSIGNED_BYTE, rgb);
} // end setPixel
void Helper::renderString(int x, int y, const char* string){
	const size_t len = strlen(string);
	glColor3f(1.0, 1.0, 1.0);
	glWindowPos2f(x, y);
	for(size_t i = 0; i < len; i++){
      glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *string);
	  string++;
	}
}
Example #3
0
void BitMap::drawBitmapText(const char * string, float x, float y)
{
	
		//string_ = string;
		const char *c;
		glWindowPos2f(x, y);

		for (c = string; *c != '\0'; c++)
		{
			glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *c);
		}
	
}
Example #4
0
void drawText( const std::string& text, float x, float y, void* font )
{
  // Save state
  glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );

  glDisable( GL_TEXTURE_2D );
  glDisable( GL_LIGHTING );
  glDisable( GL_DEPTH_TEST);

  glColor3fv( &( m_text_shadow_color.x) ); // drop shadow
  // Shift shadow one pixel to the lower right.
  glWindowPos2f(x + 1.0f, y - 1.0f);
  for( std::string::const_iterator it = text.begin(); it != text.end(); ++it )
    glutBitmapCharacter( font, *it );

  glColor3fv( &( m_text_color.x) );        // main text
  glWindowPos2f(x, y);
  for( std::string::const_iterator it = text.begin(); it != text.end(); ++it )
    glutBitmapCharacter( font, *it );

  // Restore state
  glPopAttrib();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL14_nglWindowPos2f(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jlong function_pointer) {
	glWindowPos2fPROC glWindowPos2f = (glWindowPos2fPROC)((intptr_t)function_pointer);
	glWindowPos2f(x, y);
}
Example #6
0
// rendering function, everything that needs to be updated regurlarly and redrawn go in here.
void render() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUseProgram(shaderProgramID);
	// if automatic the values get updated
	if (automanualtoggle == true )
	{

		if (toggleQuatMatrix == true)
		{

			theta += 0.02f;
			gamma += 0.015f;
			alpha += 0.01f;

		}
		if (toggleQuatMatrix == false)
		{

			beta += 0.011f; //X
			delta += 0.013f; // Z
			omega += 0.017f; // Y

		}

	}


	scaleAmount = 1.0f; //scale amount for the model, 1.0 means no particular change
	
	// Set the (M)odel matrix

	// using Matrices for the Rotation, 
	if (toggleQuatMatrix == true)
	{
		// calcualtion for the matrices in order Scale Rotation Translation
		//scale
	MathHelper::makeScale(scaleMatrix, scaleAmount, scaleAmount, scaleAmount);	
	// single rotations
	MathHelper::makeRotateX(rotXMatrix, alpha);
	MathHelper::makeRotateY(rotYMatrix, theta);
	MathHelper::makeRotateZ(rotZMatrix, gamma);
	// obtaining the final rotation around all 3 axis using the multiplicatino between 4X4 matrices function
	MathHelper::matrixMult4x4(rotXYZMatrix, rotXMatrix, rotYMatrix);
	MathHelper::matrixMult4x4(rotXYZ1Matrix, rotXYZMatrix, rotZMatrix);
	MathHelper::matrixMult4x4(tempMatrix1, rotXYZ1Matrix, scaleMatrix);
	// a copy of the rotation matrix, useful to give data to the shaders
	MathHelper::copyMatrix(rotXYZ1Matrix, allRotsMatrix);

	}

	// At last translation 
	MathHelper::makeTranslate(transMatrix, 0.0f, -6.0f, -12.0f);	// slightly back.

	//Using Quaternions for the rotation
	if (toggleQuatMatrix == false)
	{
		// rotation on the single axis
		QuatresultX = Quaternion::QuatRotate(QuatRotation, omega, 0, 1, 0);
		QuatresultY = Quaternion::QuatRotate(QuatRotation, delta, 1, 0, 0);
		QuatresultZ = Quaternion::QuatRotate(QuatRotation, beta, 0, 0, 1);


		// multiplication of the 3 rotation in one quaternion
		QuatresultXY = Quaternion::QuatMultiply(QuatresultX, QuatresultY);
		QuatresultXYZ = Quaternion::QuatMultiply(QuatresultXY, QuatresultZ);

		//quaternion gets transformed into a Matrix ready to be given to the shaders
		Quaternion::QuatToMatrix(QuatresultXYZ, rotXYZMatrix);
		
		// lets scale everything and copy the matrix just in case
		MathHelper::matrixMult4x4(tempMatrix1, rotXYZMatrix, scaleMatrix);
		MathHelper::copyMatrix(rotXYZMatrix, allRotsMatrix);
	}

	// calculation of the MODEL matrix (M)
	MathHelper::matrixMult4x4(M, transMatrix, tempMatrix1);				// ... then multiply THAT by the translate


	// VIEW matrix gets updated in case the camera is moved around
	MathHelper::makeRotateY(rotYMatrix, yaw);
	MathHelper::makeTranslate(transMatrix, camX, camY, camZ);
	MathHelper::matrixMult4x4(V, rotYMatrix, transMatrix);
	
	// pass that data to the shader variables
	glUniformMatrix4fv(modelMatrixID, 1, GL_TRUE, M);
	glUniformMatrix4fv(viewMatrixID, 1, GL_TRUE, V);
	glUniformMatrix4fv(perspectiveMatrixID, 1, GL_TRUE, P);
	glUniformMatrix4fv(allRotsMatrixID, 1, GL_TRUE, allRotsMatrix);
	glUniform4fv(lightID, 1, light);
	
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // cool effect
#ifdef USING_INDEX_BUFFER
	glDrawElements (GL_TRIANGLES, NUM_INDICES, GL_UNSIGNED_INT, NULL);
#else
	glDrawArrays(GL_TRIANGLES, 0, NUM_VERTICES);
#endif
	
	// necessary to write on screen the results of the rotation, LIGHTING needs to be disabled or the color is the same as the background...
	glDisable(GL_LIGHTING);
	glLoadIdentity();
	glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
	glColor3f(0.5f, 1.0f, 1.0f);

	float sinbeta = sin(beta);
	float sindelta = sin(delta);
	float sinomega = sin(omega);
	float sinalpha = sin(alpha);
	float sintheta = sin(theta);
	float singamma = sin(gamma);


	char output[50];


		glWindowPos2f(20, 580);
		_snprintf(output, 50, "%f", sinbeta);
		char Cfinal[50] = "Quat x rotation (sin): ";
		char* display = concat(Cfinal, output);
		glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)display);

		glWindowPos2f(20, 560);
		_snprintf(output, 50, "%f", sinomega);
		char Cfinal1[50] = "Quat y rotation (sin): ";
		char* display1 = concat(Cfinal1, output);
		glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)display1);

		glWindowPos2f(20, 540);
		_snprintf(output, 50, "%f", sindelta);
		char Cfinal2[50] = "Quat z rotation (sin): ";
		char* display2 = concat(Cfinal2, output);
		glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)display2);



		glWindowPos2f(300, 580);
		_snprintf(output, 50, "%f", sinalpha);
		char Cfinal3[50] = "Matrix x rotation (sin): ";
		char* display3 = concat(Cfinal3, output);
		glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)display3);

		glWindowPos2f(300, 560);
		_snprintf(output, 50, "%f", sintheta);
		char Cfinal4[50] = "Matrix y rotation (sin): ";
		char* display4 = concat(Cfinal4, output);
		glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)display4);

		glWindowPos2f(300, 540);
		_snprintf(output, 50, "%f", singamma);
		char Cfinal5[50] = "Matrix z rotation (sin): ";
		char* display5 = concat(Cfinal5, output);
		glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)display5);

	glEnable(GL_LIGHTING);		
	glutSwapBuffers();
	glutPostRedisplay();		
}