Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Solar system Help

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    5

    Solar system Help

    Hello everybody,
    I want to ask help for a project I make.
    I have made a complete solar system with key action for zoom in zoom out, moving along x,y,z axes on plus or minus and going up/down/right/left.
    I am now in a bit of a dilemma.
    I want to add a text window ( i have made my project in visual studio 2010 in win32 console application) where to put a text like a description of each planet to apear when i hit the left mouse button.
    E.g. When i click with the left mouse button the venus planet I want a description to apear in my text window.
    However I don't know how to put make a text window and how to add mouse action (for the mouse action I have tried but it doesn't work)
    Please help me!
    Thanks in advance.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    174
    If you really have a console application, you have two windows:
    1) for the graphics, and 2) the console window.

    Why not output your planet description into the console window?

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    5
    yes i have two windows i have tried to p;ut the name of the selected planet there but... i have not manage to correctly select the planet because i have a switch case and the default switch is:"you have nothing selected" when i click the left mouse button my planets dissapear and i nead to resize the window to see again the planets... besides that it would be beter to have the description of the planet on the graphic window... i have also tried to learn how to put font in order to make the name of the planets move along with the planets but i have not succeded.... if you could guide me ... i would be very thankfull

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    174
    Sounds like your problem has more to do with picking than windows or text.
    Get the picking working first. Find a picking tutorial on the web or in an OpenGL
    text. If done correctly picking returns a name (character string). First try to
    simply print that name to your console window to make sure you've set up
    picking correctly. THEN you can worry about displaying the character string in
    the graphics window.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    5
    I have tried to make the picking function again... no matter where have i clicked it always says that i have selected the sun... could you help me with my picking function? please.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    800
    For us to be of any help, you need to show us your code.
    Regards,
    Mobeen

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    5
    how can i add my code to the forum?

  8. #8
    Administrator Regular Contributor Khronos_webmaster's Avatar
    Join Date
    Apr 2007
    Location
    Montreal
    Posts
    148
    Please be sure that you have read the forum posting guidelines. There is a section in there about posting code.
    Webmaster Khronos.org and OpenGL.org

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    5
    here is my code:
    Code :
     
    #include "SolarSystem.h"
     
    #include "windows.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include<iostream>
    using namespace std;
    #include <gl/glut.h>
    #include <GL/glu.h>
    #include <gl/GL.h>
    #include <math.h>
     
    // Valori lumina
    GLfloat  whiteLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    GLfloat  sourceLight[] = { 0.8f, 0.8f, 0.8f, 1.0f };
    GLfloat	 lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
     
    //verificare pt incarcare texturi doar o data
    bool texturesCreated = false;
     
    //texturi
    GLuint sunTexture;
    GLuint mercuryTexture;
    GLuint venusTexture;
    GLuint earthTexture;
    GLuint moonTexture;
    GLuint marsTexture;
    GLuint jupiterTexture;
    GLuint saturnTexture;
    GLuint uranusTexture;
    GLuint neptuneTexture;
    GLuint plutoTexture;
    GLuint starsTexture;
     
    //pozitia si rotatia soarelui
    GLfloat fSunX = 0.0f;
    GLfloat fSunY = 0.0f;
    GLfloat fSunZ = -300.0f;
    GLfloat fCamX = 0.0f;
    GLfloat fCamY = 0.0f;
    GLfloat fCamZ = 0.0f;
    GLfloat fSunRotX = 0.0f;
    GLfloat fSunRotY = 0.0f;
    GLfloat fSunRotZ = 0.0f;
     
    //definitii functii
    void keyDown(unsigned char, int, int);
    unsigned char *LoadBmp(char *fn, int *wi, int *hi);
    void GenerateTextures(char *, int);
    void InitialiseTextures(void);
     
     
    void gl_init(int w, int h);
    void gl_select(int x, int y);
    void mouseClick();
    void mousedw(int x, int y, int but);
    void list_hits(GLint hits, GLuint *names);
     
     
    //definitii pt click
    #define Sun 1
    #define Mercur 2
    #define Venus 3
    #define Terra 4
    #define Moon 5
    #define Marte 6
    #define Jupiter 7
    #define Saturn 8
    #define Uranus 9
    #define Pluto 10
    #define Neptun 11
    #define MAXSELECT 100
    #define BUFSIZE 512
     
     
    #define SW 450
    #define SH 450
     
     
    GLuint selectBuf[BUFSIZE];
    GLuint buf_selectie[MAXSELECT];
    GLint windH;
    GLint viewport [4];
     
    // Scena
    void RenderScene(void)
    {
    	//picking initializare stiva
    	glInitNames();
     
     
     
     
     
    	GLUquadricObj* pObj;
    	// Unghiul de revolutie al planetelor
    	static float fMoonRot = 0.0f;
    	static float fEarthRot = 0.0f;
    	static float fMercuryRot = 0.0f;
    	static float fVenusRot = 0.0f;
    	static float fMarsRot = 0.0f;
    	static float fJupiterRot = 0.0f;
    	static float fSaturnRot = 0.0f;
    	static float fUranusRot = 0.0f;
    	static float fNeptuneRot = 0.0f;
    	static float fPlutoRot = 0.0f;
     
    	// 
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	//Salvarea matricii cu stari 
    	glMatrixMode(GL_MODELVIEW);
    	glPushMatrix();
     
     
    	// translatarea scenei in functie de soare
    	glTranslatef(fSunX, fSunY, fSunZ);	
     
    	// Soare
    	glDisable(GL_LIGHTING);
     
    	pObj = gluNewQuadric(); //creare obiecte cuadrice pt pObj
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, sunTexture); //setare textura soare
     
    	//Rotatia soarelui in jurul axei sale
    	glRotatef(fSunRotX, 1.0f, 0.0f, 0.0f); //rotatie soare in jurul axei x
    	glRotatef(fSunRotY, 0.0f, 1.0f, 0.0f); //rotatie soare in jurul axei y
    	glRotatef(fSunRotZ, 0.0f, 0.0f, 1.0f); //rotatie soare in jurul axei z
    	glLoadName(Sun);
    	gluSphere(pObj, 33.0f, 30, 17); //draw sphere for the sun
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); //eliberare obiect pObj
     
    	glEnable(GL_LIGHTING);
     
    	// mutarea luminii la pozitia soareui
    	glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
     
    #pragma region skybox
     
    	// memorare matrice currenta
    	glPushMatrix();
     
     
     
    	glPushAttrib(GL_ENABLE_BIT);
    	glEnable(GL_TEXTURE_2D);
     
     
    	glColor4f(1,1,1,1);
    	GLfloat val = 450.0f;
     
    	// Render the front quad
    	glBindTexture(GL_TEXTURE_2D, starsTexture);
    	glBegin(GL_QUADS); 
    	glTexCoord2f(0, 0); glVertex3f(val, -val, val);
    	glTexCoord2f(1, 0); glVertex3f(-val, -val, val);
    	glTexCoord2f(1, 1); glVertex3f(-val, val, val);
    	glTexCoord2f(0, 1); glVertex3f(val, val, val);
    	glEnd();
     
    	// Render the left quad
    	glBindTexture(GL_TEXTURE_2D, starsTexture);
    	glBegin(GL_QUADS);
    	glTexCoord2f(0, 0); glVertex3f(val, -val, -val);
    	glTexCoord2f(1, 0); glVertex3f(val, -val, val);
    	glTexCoord2f(1, 1); glVertex3f(val, val, val);
    	glTexCoord2f(0, 1); glVertex3f(val, val, -val);
    	glEnd();
     
    	// Render the back quad
    	glBindTexture(GL_TEXTURE_2D, starsTexture);
    	glBegin(GL_QUADS);
    	glTexCoord2f(0, 0); glVertex3f(-val, -val, -val);
    	glTexCoord2f(1, 0); glVertex3f(val, -val, -val);
    	glTexCoord2f(1, 1); glVertex3f(val, val, -val);
    	glTexCoord2f(0, 1); glVertex3f(-val, val, -val);
     
    	glEnd();
     
    	// Render the right quad
    	glBindTexture(GL_TEXTURE_2D, starsTexture);
    	glBegin(GL_QUADS);
    	glTexCoord2f(0, 0); glVertex3f(-val, val, -val);
    	glTexCoord2f(1, 0); glVertex3f(-val, val, val);
    	glTexCoord2f(1, 1); glVertex3f(-val, -val, val);
    	glTexCoord2f(0, 1); glVertex3f(-val, -val, -val);
    	glEnd();
     
    	// Render the top quad
    	glBindTexture(GL_TEXTURE_2D, starsTexture);
    	glBegin(GL_QUADS);
    	glTexCoord2f(0, 0); glVertex3f(val, val, -val);
    	glTexCoord2f(1, 0); glVertex3f(val, val, val);
    	glTexCoord2f(1, 1); glVertex3f(-val, val, val);
    	glTexCoord2f(0, 1); glVertex3f(-val, val, -val);
    	glEnd();
     
    	// Render the bottom quad
    	glBindTexture(GL_TEXTURE_2D, starsTexture);
    	glBegin(GL_QUADS);
    	glTexCoord2f(0, 0); glVertex3f(-val, -val, -val);
    	glTexCoord2f(1, 0); glVertex3f(-val, -val, val);
    	glTexCoord2f(1, 1); glVertex3f(val, -val, val);
    	glTexCoord2f(0, 1); glVertex3f(val, -val, -val);
    	glEnd();
     
    	// Resetare matrice
    	glPopAttrib();
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region mercury 
     
    	//Mercur
    	glPushMatrix(); //salvare matrice
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, mercuryTexture); //setare textura mercur
     
    	//coord de rotatie pt mercur
    	glRotatef(fMercuryRot, 0.0f, 2.0f, 0.3f);
     
    	//desenare Mercur
    	glTranslatef(45.0f,-15.0f,0.0f); //mutare mercur la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotire
    	glRotatef(fMercuryRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Mercur);
    	gluSphere(pObj, 8.0f, 30, 17); //desenare sfera
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj);
     
    	//viteza de rotatie
    	fMercuryRot += 20.0f;
    	//resetare rotatie
    	if(fMercuryRot >= 360.0f)
    		fMercuryRot = 0.0f;
     
    	glPopMatrix(); //resetare matrice
     
    #pragma endregion
     
    #pragma region venus
    	//Venus
    	glPushMatrix(); //salvare matrice
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, venusTexture); //setare textura venus
     
    	//coord de rotire pt venus
    	glRotatef(fVenusRot, 0.0f, 1.0f, 0.0f);
     
    	//Desenare Venus
    	glTranslatef(65.0f,0.0f,0.0f); //mutare venus la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotire
    	glRotatef(fVenusRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Venus);
    	gluSphere(pObj, 14.0f, 30, 17); //desenare sfera pt venus
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); 
     
    	//viteza rotire
    	fVenusRot += 10.0f;
    	//resetare rotire
    	if(fVenusRot >= 360.0f)
    		fVenusRot = 0.0f;
     
     
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region marte
    	//Marte
    	glPushMatrix();
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, marsTexture); //setare textura marte
     
    	//coord de rotire pt marte
    	glRotatef(fMarsRot, 0.0f, 1.0f, 0.3f);
     
    	//desenare marte
    	glTranslatef(130.0f,0.0f,0.0f); //pozitionare marte la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotatie 
    	glRotatef(fMarsRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Marte);
    	gluSphere(pObj, 7.0f, 30, 17); //desenare sfera
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj);
     
    	//viteza rotatie
    	fMarsRot += 4.0f;
    	//resetare rotatie
    	if(fMarsRot >= 360.0f)
    		fMarsRot = 0.0f;
     
     
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region jupiter
    	//Jupiter
    	glPushMatrix(); 
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, jupiterTexture); //setare textura jupiter
     
    	//coord de rotire pt jupiter
    	glRotatef(fJupiterRot, 0.0f, 1.0f, -0.3f);
     
    	//Desenare Jupiter
    	glTranslatef(200.0f,0.0f,0.0f); //pozitionare jupiter la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotatie 
    	glRotatef(fJupiterRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Jupiter);
    	gluSphere(pObj, 22.0f, 30, 17); //desenare sfera
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); 
     
    	//setare viteza de rotatie 
    	fJupiterRot += 2.0f;
    	//resetare rotatie
    	if(fJupiterRot >= 360.0f)
    		fJupiterRot = 0.0f;
     
     
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region saturn
    	//Saturn
    	glPushMatrix(); 
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, saturnTexture); //setare textura Saturn
     
    	//Coord de rotire pt Saturn
    	glRotatef(fSaturnRot, 0.0f, 0.8f, -0.2f);
     
    	//Desenare Saturn
    	glTranslatef(245.0f,0.0f,0.0f); //setare pozitie Saturn la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //Rotatie
    	glRotatef(fSaturnRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Saturn);
    	gluSphere(pObj, 20.0f, 30, 17); //desenare sfera
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); 
     
    	//viteza rotatie
    	fSaturnRot += 1.5f;
    	//resetare rotatie
    	if(fSaturnRot >= 360.0f)
    		fSaturnRot = 0.0f;
     
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region uranus
    	//Uranus
    	glPushMatrix();
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, uranusTexture); //setare textura pt Uranus
     
    	//coord de rotire pt Uranus
    	glRotatef(fUranusRot, 0.0f, 0.8f, 0.2f);
     
    	//Desenare Uranus
    	glTranslatef(285.0f,0.0f,0.0f); //pozitionare Uranus la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotatie 
    	glRotatef(fUranusRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Uranus);
    	gluSphere(pObj, 10.0f, 30, 17); //desenare sfera
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); 
     
    	//viteza de rotatie
    	fUranusRot += 1.0f;
    	//resetare rotatie
    	if(fUranusRot >= 360.0f)
    		fUranusRot = 0.0f;
     
     
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region neptun
    	//Neptun
    	glPushMatrix();
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, neptuneTexture); //setare textura pt neptun
     
    	//coord de rotatie pt neptun
    	glRotatef(fNeptuneRot, 0.0f, 0.8f, 0.2f);
     
    	//Desenare Neptune
    	glTranslatef(315.0f,0.0f,0.0f); //setare pozitie la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotire 
    	glRotatef(fNeptuneRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Neptun);
    	gluSphere(pObj, 12.0f, 30, 17); //desenare sfera pt neptun
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); 
     
    	//viteza de rotatie
    	fNeptuneRot += 0.6f;
    	//resetare rotatie
    	if(fNeptuneRot >= 360.0f)
    		fNeptuneRot = 0.0f;
     
     
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region pluto
    	//Pluto
    	glPushMatrix(); 
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, plutoTexture); //setare textura pt pluto
     
    	//coord de rotatie pt Pluto
    	glRotatef(fPlutoRot, 0.0f, 0.8f, 0.2f);
     
    	//Desenare Pluto
    	glTranslatef(350.0f,0.0f,0.0f); //setare la distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotatie 
    	glRotatef(fPlutoRot * 3, 0.0f, 0.0f, 1.0f); //rotatie in jurul axei sale
    	glLoadName(Pluto);
    	gluSphere(pObj, 12.0f, 30, 17); //desenare sfera
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); 
     
    	//viteza de rotatie
    	fPlutoRot += 0.2f;
    	//
    	if(fPlutoRot >= 360.0f)
    		fPlutoRot = 0.0f;
     
     
    	glPopMatrix();
     
    #pragma endregion
     
    #pragma region Terra
    	//Pamant
    	glPushMatrix();
     
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, earthTexture);//setare textura
     
    	// coord de rotire pt pamant
    	glRotatef(fEarthRot, 0.0f, 1.0f, 0.0f); //rotatie in jurul soarelui
     
    	// Desenare Terra
    	glTranslatef(100.0f,0.0f,0.0f); //setare distanta de soare
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotire
    	glRotatef(fEarthRot * 3, 0.0f, 0.0f, 1.0f); //rotire in jurul axei sale
    	glLoadName(Terra);
    	gluSphere(pObj, 16.0f, 30, 17); //desenare sfera
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj); 
     
    #pragma region earthMoon
    	// Desenare Luna
    	pObj = gluNewQuadric();
    	gluQuadricTexture(pObj,GL_TRUE);
     
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, moonTexture); //setare textura Luna
    	glRotatef(fMoonRot,0.0f, 0.0f, 1.0f); //rotire luna in jurul pamantului
    	glTranslatef(25.0f, 0.0f, 0.0f); //distanta fata de pamant
    	glRotatef(270.0f, 1.0f, 0.0f, 0.0f); //rotire
    	glRotatef(fMoonRot * 3, 0.0f, 0.0f, 1.0f); //rotire in jurul axei sale
     
    	//viteza de rotatie
    	fMoonRot+= 15.0f;
    	//
    	if(fMoonRot >= 360.0f)
    		fMoonRot = 0.0f;
    	glLoadName(Moon);
    	gluSphere(pObj, 4.0f, 30, 17); //desenare sfera pt luna
    	glDisable(GL_TEXTURE_2D);
     
    	gluDeleteQuadric(pObj);
     
    	glPopMatrix();	
    #pragma endregion
     
     
    	//viteza de rotire a pamantului
    	fEarthRot += 5.0f;
    	//
    	if(fEarthRot >= 360.0f)
    		fEarthRot = 0.0f;
     
    	glPopMatrix();	// 
     
    #pragma endregion
     
    	// Show  image
    	glutSwapBuffers();
     
    }
     
     
     
    void SetupRC()
    {
    	//valoare si coord lumina
    	glEnable(GL_DEPTH_TEST);	// 
    	glFrontFace(GL_CCW);		// invers acelor de ceasornic (pt sfere)
    	glEnable(GL_CULL_FACE);		//
     
    	// on lumina
    	glEnable(GL_LIGHTING);
     
    	// setare lumina
    	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,whiteLight);
     
    	glLightfv(GL_LIGHT0,GL_AMBIENT_AND_DIFFUSE,sourceLight);
    	glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
    	glEnable(GL_LIGHT0);
     
    	//
    	glEnable(GL_COLOR_MATERIAL);
     
    	// 
    	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
     
    	// setare background negru
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
    }
     
    void TimerFunc(int value)
    {
    	glutPostRedisplay();
    	glutTimerFunc(100, TimerFunc, 1);
    }
     
    //posibilitate de minimizare si maximizare de catre user
    void ChangeSize(int w, int h)
    {
    	GLfloat fAspect;
     
    	// 
    	if(h == 0)
    		h = 1;
     
    	// setare vedere in functie de marimea ferestrei
    	glViewport(0, 0, w, h);
     
    	// aspect in functie de marimea ferestrei
    	fAspect = (GLfloat)w/(GLfloat)h;
     
    	//  setare coord pt ferestra
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
     
    	// modul de vizionare
    	gluPerspective(45.0f, fAspect, 1.0, 1600.0);
     
    	// 
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
     
     
    void gl_init(int w, int h)
    {
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
    	glViewport(0, 0, w, h);
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
     
    	gluPerspective(60.0, 1.0, 0.0001, 1000.0);
     
    	glMatrixMode(GL_MODELVIEW);
    }
     
    void list_hits(GLint hits, GLuint *names)
    {
     
     
    	printf("%d hits:\n", hits);
     
    	switch(hits)
    	{
     
    	case Mercur:
    		cout<<"Ati selectat Planeta Mercur"<<endl;
    		break;
    	case Sun:
    		cout<<"Ati selectat Soarele"<<endl;
    		break;
    	case Saturn:
    		cout<<"Ati selectat Planeta Saturn"<<endl;
    		break;
    	case Neptun:
    		cout<<"Ati selectat Planeta Neptun"<<endl;
    		break;
    	case Uranus:
    		cout<<"Ati selectat Planeta Uranus"<<endl;
    		break;
    	case Jupiter:
    		cout<<"Ati selectat Planeta Jupiter"<<endl;
    		break;
    	case Marte:
    		cout<<"Ati selectat Planeta Marte"<<endl;
    		break;
    	case Venus:
    		cout<<"Ati selectat Planeta Venus"<<endl;
    		break;
    	case Pluto:
    		cout<<"Ati selectat Planeta Pluto"<<endl;
    		break;
    	case Terra:
    		cout<<"Ati selectat Planeta Pamant"<<endl;
    		break;
    	case Moon:
    		cout<<"Ati selectat Luna"<<endl;
    		break;
    	default:
    		cout<<"Nu ati selectat nimic"<<endl;
    		break;
     
    	}
     
    }
     
    void gl_select(int x, int y)
    {
    	GLuint buff[64] = {0};
    	GLint hits, view[4];
     
    	/*
    	This choose the buffer where store the values for the selection data
    	*/
    	glSelectBuffer(64, buff);
     
    	/*
    	This retrieve info about the viewport
    	*/
    	glGetIntegerv(GL_VIEWPORT, view);
     
    	/*
    	Switching in selecton mode
    	*/
    	glRenderMode(GL_SELECT);
     
    	/*
    	Clearing the name's stack
    	This stack contains all the info about the objects
    	*/
    	glInitNames();
     
    	/*
    	Now fill the stack with one element (or glLoadName will generate an error)
    	*/
    	glLoadName(0);
     
    	/*
    	Now modify the vieving volume, restricting selection area around the cursor
    	*/
    	glMatrixMode(GL_PROJECTION);
    	glPushMatrix();
    	glLoadIdentity();
     
    	/*
    	restrict the draw to an area around the cursor
    	*/
    	gluPickMatrix(x, y, 0.2, 0.2, view);
    	gluPerspective(60, 0.5, 0.0001, 1000.0);
     
    	/*
    	Draw the objects onto the screen
    	*/
    	glMatrixMode(GL_MODELVIEW);
     
    	/*
    	draw only the names in the stack, and fill the array
    	*/
    	glutSwapBuffers();
    	RenderScene();
     
    	/*
    	Do you remeber? We do pushMatrix in PROJECTION mode
    	*/
    	glMatrixMode(GL_PROJECTION);
    	glPopMatrix();
     
    	/*
    	get number of objects drawed in that area
    	and return to render mode
    	*/
    	hits = glRenderMode(GL_RENDER);
     
    	/*
    	Print a list of the objects
    	*/
    	list_hits(hits, buff);
     
    	/*
    	uncomment this to show the whole buffer
    	* /
    	gl_selall(hits, buff);
    	*/
     
    	glMatrixMode(GL_MODELVIEW);
    }
     
    void mousedw(int x, int y, int but)
    {
    	printf("Mouse button %d pressed at %d %d\n", but, x, y);
    	gl_select(x,SH-y); //Important: gl (0,0) ist bottom left but window coords (0,0) are top left so we have to change this!
    }
     
     
    void mouseClick(int button, int state, int x, int y)
    {
    	if 	((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN))
    	{
    		mousedw(x, y, button);
    	}
    }
     
     
     
    int main(int argc, char* argv[])
    {
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	///glutInitWindowSize(1000, 600);
    	glutInitWindowSize(SW, SH);
    	glutInitWindowPosition(0, 0);
    	glutCreateWindow("Solar System"); //numele ferestrei
    	glutReshapeFunc(ChangeSize);
    	glutDisplayFunc(RenderScene);
    	glutKeyboardFunc(keyDown); //pt taste
    	//INREGISTRARIILE FUNCTIILOR PT MOUSE
    	glutMouseFunc(mouseClick);
    	//	glutMouseFunc(mouse);
    	gl_init(SW, SH);
     
     
    	glutTimerFunc(250, TimerFunc, 1);
    	SetupRC();
    	//verificare textura
    	if (texturesCreated == false)
    	{
    		InitialiseTextures();
    		texturesCreated = true; //
    	}
    	glutMainLoop();
     
    	return 0;
    }
     
    //controale
    void keyDown(unsigned char key, int x, int y) 
    {
    	//Moves the camera to the right
    	if (key == 'A' || key == 'a')
    	{
    		fSunX += 3.0f;
    		fCamX += -3.0f;
    	}
    	//Moves the camera to the left
    	if (key == 'D' || key == 'd')
    	{
    		fSunX += -3.0f;
    		fCamX += 3.0f;
    	}
    	//Moves the camera up
    	if (key == 'W' || key == 'w')
    	{
    		fSunY += -3.0f;
    		fCamY += 3.0f;
    	}
    	//Moves the camera down
    	if (key == 'S' || key == 's')
    	{
    		fSunY += 3.0f;
    		fCamY += -3.0f;
    	}
    	//Zooms the camera out
    	if (key == 'X' || key == 'x')
    	{
    		fSunZ += -3.0f;
    		fCamZ += 3.0f;
    	}
    	//Zooms the camera in
    	if (key == 'Z' || key == 'z')
    	{
    		fSunZ += 3.0f;
    		fCamZ += -3.0f;
    	}
    	//Rotates the camera along the positive X axis
    	if (key == 'J' || key == 'j')
    	{
    		fSunRotY += 3.0f;
    	}
    	//Rotates the camera along the negative X axis
    	if (key == 'L' || key == 'l')
    	{
    		fSunRotY += -3.0f;
    	}
    	//Rotates the camera along the negative Y axis
    	if (key == 'I' || key == 'i')
    	{
    		fSunRotX += 3.0f;
    	}
    	//Rotates the camera along the positive Y axis
    	if (key == 'K' || key == 'k')
    	{
    		fSunRotX += -3.0f;
    	}
    	//Rotates the camera along the positive Z axis
    	if (key == 'M' || key == 'm')
    	{
    		fSunRotZ += -3.0f;
    	}
    	//Rotates the camera along the positive Z axis
    	if (key == 'N' || key == 'n')
    	{
    		fSunRotZ += 3.0f;
    	}
     
    }
     
    unsigned char *LoadBmp(char *fn, int *wi, int *hi)
    {
    	BITMAPFILEHEADER bmfh;
    	BITMAPINFOHEADER bmih;
    	WORD bits;
    	FILE *t24;
    	unsigned char *lpBitmapBits;
    	long imagesize,nc;
     
    	// citire bitmap
    	t24=fopen((char *)fn,"rb");
    	if(t24 == NULL){printf("Could not open input file\n"); exit(0);}
    	fread((char *)&bmfh,sizeof(BITMAPFILEHEADER),1,t24);
    	fread((char *)&bmih,sizeof(BITMAPINFOHEADER),1,t24);
    	if(bmih.biClrUsed != 0)nc=bmih.biClrUsed;
    	else{
    		bits = bmih.biBitCount;
    		switch (bits){
    		case 1:    nc=2;   break;
    		case 4:    nc=16;  break;
    		case 8:    nc=256; break;
    		default:   nc=0;   break;
    		}
    	}
    	if(nc > 0){printf("Cannot handle paletted image\n"); exit(0);}
    	imagesize=bmfh.bfSize-bmfh.bfOffBits;
    	if((lpBitmapBits=(unsigned char *)malloc(imagesize)) == NULL){ fclose(t24); exit (0); }
    	fread((char *)lpBitmapBits,imagesize,1,t24);
    	fclose(t24);
    	*wi=bmih.biWidth; *hi=bmih.biHeight;
    	return lpBitmapBits;
    }
     
     
     
    void InitialiseTextures()
    {
    	//load texturi
    	GenerateTextures("earth.bmp", 1);
    	GenerateTextures("sun.bmp", 2);
    	GenerateTextures("mercur.bmp", 3);
    	GenerateTextures("venus.bmp", 4);
    	GenerateTextures("moon.bmp", 5);
    	GenerateTextures("marte.bmp", 6);
    	GenerateTextures("jupiter.bmp", 7);
    	GenerateTextures("saturn.bmp", 8);
    	GenerateTextures("uranus.bmp", 9);
    	GenerateTextures("neptun.bmp", 10);
    	GenerateTextures("pluto.bmp", 11);
    	GenerateTextures("stars.bmp", 12);
    }
     
    //
    void GenerateTextures(char *name, int i)
    {
    	unsigned char *pix;
    	int w,h;
    	glEnable(GL_TEXTURE_2D);
    	//asigane pt texturi
    	pix=LoadBmp(name,&w,&h);	
    	if (i == 1) //gets & sets textura pt pamant
    	{
    		glGenTextures(1, &earthTexture);
    		glBindTexture(GL_TEXTURE_2D, earthTexture);
    	}
    	if (i == 2) //gets & sets textura pt soare
    	{
    		glGenTextures(1, &sunTexture);
    		glBindTexture(GL_TEXTURE_2D, sunTexture);
    	}
    	if (i == 3) //gets & sets textura pt mercur
    	{
    		glGenTextures(1, &mercuryTexture);
    		glBindTexture(GL_TEXTURE_2D, mercuryTexture);
    	}
    	if (i == 4) //gets & sets textura pt venus
    	{
    		glGenTextures(1, &venusTexture);
    		glBindTexture(GL_TEXTURE_2D, venusTexture);
    	}
    	if (i == 5) //gets & sets textura pt luna
    	{
    		glGenTextures(1, &moonTexture);
    		glBindTexture(GL_TEXTURE_2D, moonTexture);
    	}
    	if (i == 6) //gets & sets textura pt marte
    	{
    		glGenTextures(1, &marsTexture);
    		glBindTexture(GL_TEXTURE_2D, marsTexture);
    	}
    	if (i == 7) //gets & sets textura pt jupiter
    	{
    		glGenTextures(1, &jupiterTexture);
    		glBindTexture(GL_TEXTURE_2D, jupiterTexture);
    	}
    	if (i == 8) //gets & sets textura pt saturn
    	{
    		glGenTextures(1, &saturnTexture);
    		glBindTexture(GL_TEXTURE_2D, saturnTexture);
    	}
    	if (i == 9) //gets & setstextura pt uranus
    	{
    		glGenTextures(1, &uranusTexture);
    		glBindTexture(GL_TEXTURE_2D, uranusTexture);
    	}
    	if (i == 10) //gets & sets textura pt neptun
    	{
    		glGenTextures(1, &neptuneTexture);
    		glBindTexture(GL_TEXTURE_2D, neptuneTexture);
    	}
    	if (i == 11) //gets & sets textura pt pluto
    	{
    		glGenTextures(1, &plutoTexture);
    		glBindTexture(GL_TEXTURE_2D, plutoTexture);
    	}
    	if (i == 12) //gets & sets textura pt stele
    	{
    		glGenTextures(1, &starsTexture);
    		glBindTexture(GL_TEXTURE_2D, starsTexture);
    	}
    	glTexImage2D(	GL_TEXTURE_2D, 0, GL_RGB, w, h,
    		0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pix);
    	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	free(pix); //eliberare pix
    	glDisable(GL_TEXTURE_2D);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •