void draw(Pixmap pixmap, XInfo &xinfo){	//NOTE: 'pixmap' is only used for double buffering, if applicable
		if (x>-50 && x<800){
			if (day) drawSun(xinfo, xinfo.gc[0], x,y);
			else drawMoon(xinfo, xinfo.gc[0], xinfo.gc[2], x,y);
		}
	}
Exemple #2
0
int main(int argc, char *argv[])
{
	chdir("/Users/tjgreen/Documents/OpenGL/Sol");
	
	GLFWwindow *window = setupGLFW();
	GLuint skyboxTexture = initCubemap();
	
	//GLFWwindow* window2 = glfwCreateWindow(500, 500, "SolarSystem", NULL, NULL);
	//glfwMakeContextCurrent(window2);
	
	/*Cross platform compatibility stuff uncomment if not on mac
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
  		printf(stderr, "Error: %s\n", glewGetErrorString(err));
	}*/
	
	sunTexture = loadTexture("include/textures/Planets/sun2.jpg");
	sunNormal = loadTexture("include/textures/Planets/sunNormal.png");
	planetBuilder();
	init();
	createPerspectiveMatrix();
	
	initializePlanetButtons();
	
	glEnable(GL_CULL_FACE);
	glEnable(GL_MULTISAMPLE);
	glCullFace(GL_BACK);
	attachGUIShaders();
	
	float fpsFrames= 0;
	float lastTime = 0;
	while(!glfwWindowShouldClose(window))
	{
		GLfloat currentFrame = glfwGetTime();
        deltaTime = currentFrame - lastFrame;
        lastFrame = currentFrame;
        
        fpsFrames++;
		if(currentFrame - lastTime >= 1.0)
		{
			//printf("%f\n", 1000/fpsFrames);
			fpsFrames = 0;
			lastTime += 1.0;
		}
        
		glfwPollEvents();
		doMovement();
		
		glfwPollEvents();
		glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, WIDTH, HEIGHT);

		drawSkybox(skyboxTexture);
		drawSun();
		drawPlanet();
		//glFrontFace(GL_CW);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		drawAtmosphere();
		glDisable(GL_BLEND);
		//glFrontFace(GL_CCW);
		drawObj();
		drawMoon();
		
		//drawButton(button1);
		//drawPlanetButtons();
		
		if(stopRotation == 0){
			for(int i = 0; i < 11; i++)
			{
				orbitSpeedArray[i] += 0.1/planetInstanceArray[i].orbit;
			}
			for(int i = 0; i < 11; i++)
			{
				rotationSpeedArray[i] += 0.1/planetInstanceArray[i].day;
			}
			thetaY += 0.1;
		}
		
		glfwSwapBuffers(window);
	}
	
	glDeleteVertexArrays(1, &planetVAO);
    glDeleteBuffers(1, &planetVBO);
	
	glfwTerminate();
	return 0;
}