[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
OpenGL problem part 2
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 9
Thread images: 1
File: 1410017429350.jpg (93 KB, 630x566) Image search: [Google]
1410017429350.jpg
93 KB, 630x566
Bros, I am in desperate time. I need help with OpenGL project (Mini Solar system) Visual Studio under Windows. I have the whole file and it works (renders Sun, Earth and Moon), but it should generate all planets with colors. Can some bro validate the code and tell what to do or change?
Would be really grateful!
>>
#define GLUT_DISABLE_ATEXIT_HACK
#include <cstdlib>
#include <iostream>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <time.h>
#include <windows.h>
#include <vector>
#include <algorithm>
#include <GL/glxew.h>
#include <GL/wglew.h>


GLPFrame frameCamera;

enum
{

PERSP,
EXIT
};

GLint rzut = PERSP;
GLfloat alfa1 = 0.0f;
GLfloat alfa2 = 0.0f;
GLfloat alfa3 = 0.0f;
GLfloat alfa4 = 0.0f;
GLfloat alfa5 = 0.0f;
GLfloat alfa6 = 0.0f;
GLfloat alfa7 = 0.0f;
GLfloat alfa8 = 0.0f;
float angle1 = 0.0f;
float angle2 = 0.0f;
float angle3 = 0.0f;
float angle4 = 0.0f;
float angle5 = 0.0f;
float angle6 = 0.0f;
float angle7 = 0.0f;
float angle8 = 0.0f;
GLfloat xx = 0.0f;
GLfloat yy = 0.0f;
GLfloat zz = 0.0f;
GLdouble fory = 90;
int iCull = 0;
int iOutline = 0;
int iDepth = 0;
void Ustawienia()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glShadeModel(GL_SMOOTH);
glFrontFace(GL_CW);
glpInitFrame(&frameCamera);
glpMoveFrameForward(&frameCamera, -80);
glpMoveFrameUp(&frameCamera, 5);
}
void Wyjscie()
{
}
void Podloga()
{
GLfloat Rozmiar = 100.0f;
GLfloat KW_x;
GLfloat KW_z;
GLfloat Rozm_kwad = 2.0f;
bool flaga = 0;
for (KW_x = -Rozmiar; KW_x <= Rozmiar; KW_x += Rozm_kwad)
{
/**/
for (KW_z = -Rozmiar; KW_z <= Rozmiar; KW_z += Rozm_kwad)
{
if (flaga == 0)
{
glColor3f(0.8f, 0.1f, 0.1f);
flaga = 1;
}
else
{
glColor3f(0.1f, 0.1f, 0.8f);
flaga = 0;
}
glBegin(GL_QUADS);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(KW_x, 0.0f, KW_z);
glVertex3f(KW_x, 0.0f, KW_z + Rozm_kwad);
glVertex3f(KW_x + Rozm_kwad, 0.0f, KW_z + Rozm_kwad);
glVertex3f(KW_x + Rozm_kwad, 0.0f, KW_z);
glEnd();
}
}
}
>>
void Rys_aktorow(GLint czy_cien)
{
float x1 = 0;
float y1 = 0;
float z1 = 0;
float x2 = 0;
float y2 = 0;
float z2 = 0;
float x3 = 0;
float y3 = 0;
float z3 = 0;
float x4 = 0;
float y4 = 0;
float z4 = 0;
float z5 = 0;
float z6 = 0;


alfa1 += 1.0;
alfa2 += 1.0;
alfa3 += 1.0;
alfa4 += 1.0;
alfa5 += 1.0;
alfa6 += 1.0;
alfa7 += 1.0;
alfa8 += 1.0;

//ziemia
angle1 += 0.02f;

//mars
angle3 += 0.03f;

//Jowisz
angle4 += 0.04f;
//księżyc

//Neptun
angle5 += 0.05f;

//Saturn
angle6 += 0.06f;

//Uran
angle6 += 0.06f;

//Pluton
angle6 += 0.06f;

//księżyc
angle2 += 0.1f;
if (angle2 >= (2.0f*3.14159f)*1.0f)
angle2 = 0.0f;

/*glColor3f(1.0,0.0,0.0);
glPushMatrix();
glRotatef(alfa1,1.0f,0.0f,0.0f);
glRotatef(alfa2,0.0f,1.0f,0.0f);
glutSolidCube(15.0f);
glPopMatrix();

glPushMatrix();
glTranslatef(xx,yy,zz);
glColor3f(0.0f,0.0f,1.0f);
glutSolidSphere(10.0f,20,20);
glPopMatrix();*/
>>
//glPushMatrix();
//słońce
glPushMatrix();
glRotatef(alfa1, 1.0f, 0.0f, 0.0f);
//kolor kuli
glColor3f(1.0f, 1.0f, 0.0f);
glutWireSphere(20.0f, 20, 20);
glPopMatrix();

glPushMatrix();
//orbita ziemi
glRotatef(-30, 0, 1, 1);
glPushMatrix();
glColor3f(0, 0, 1);
for (float angle = 0.0f; angle <= (2.0f*3.14159f)*1.0f; angle += 0.001f)
{
glBegin(GL_POINTS);
x1 = 50.0f*sin(angle);
z1 = 50.0f*cos(angle);
glVertex3f(x1, y1, z1);
glEnd();
}
glPopMatrix();

//ziemia
glPushMatrix();
x1 = 50.0f*sin(angle1);
z1 = 50.0f*cos(angle1);
glTranslatef(x1, y1, z1);
glRotatef(alfa2, x1, y1, z1);
glutWireSphere(3.0f, 20, 20);
glPopMatrix();
//glPopMatrix();
//księżyc
glColor3f(1.0f, 1.0f, 1.0f);
glPushMatrix();
glTranslatef(x1, y1, z1);
y2 = 5.0f*sin(angle2);
z2 = 5.0f*cos(angle2);
glTranslatef(x2, y2, z2);
glutWireSphere(0.4f, 20, 20);
glPopMatrix();
glPopMatrix();

glPushMatrix();
//orbita marsa
glRotatef(-50, 0, 1, 2);
glPushMatrix();
glColor3f(0, 0, 1);
for (float angle = 0.0f; angle <= (2.0f*3.14159f)*1.0f; angle += 0.001f)
{
glBegin(GL_POINTS);
x1 = 50.0f*sin(angle);
z1 = 50.0f*cos(angle);
glVertex3f(x1, y1, z1);
glEnd();
}
glPopMatrix();

//mars
glColor3f(1.0f, 0.0f, 0.0f);
glPushMatrix();
x1 = 50.0f*sin(angle3);
z1 = 50.0f*cos(angle3);
glTranslatef(x1, y1, z1);
glRotatef(alfa3, x1, y1, z1);
glutWireSphere(5.0f, 20, 20);
glPopMatrix();
glPopMatrix();

glPushMatrix();
//orbita Jowisz
glRotatef(70, 0, 1, 4);
glPushMatrix();
glColor3f(0, 0, 1);
for (float angle = 0.0f; angle <= (2.0f*3.14159f)*1.0f; angle += 0.001f)
{
glBegin(GL_POINTS);
x1 = 50.0f*sin(angle);
z1 = 50.0f*cos(angle);
glVertex3f(x1, y1, z1);
glEnd();
}
glPopMatrix();
>>
//Jowisz
glColor3f(15.0f, 0.0f, 3.0f);
glPushMatrix();
x1 = 50.0f*sin(angle4);
z1 = 50.0f*cos(angle4);
glTranslatef(x1, y1, z1);
glRotatef(alfa4, x1, y1, z1);
glutWireSphere(7.0f, 20, 20);
glPopMatrix();
glPopMatrix();
//glutWireCube(10.0f);

//orbita Neptun
glRotatef(-75, 0, 1, 2);
glPushMatrix();
glColor3f(0, 0, 1);
for (float angle = 0.0f; angle <= (2.0f*3.14159f)*1.0f; angle += 0.001f)
{
glBegin(GL_POINTS);
x1 = 50.0f*sin(angle);
z1 = 50.0f*cos(angle);
glVertex3f(x1, y1, z1);
glEnd();
}
glPopMatrix();

//Neptun
glColor3f(5.0f, 0.0f, 3.0f);
glPushMatrix();
x1 = 50.0f*sin(angle5);
z1 = 50.0f*cos(angle5);
glTranslatef(x1, y1, z1);
glRotatef(alfa5, x1, y1, z1);
glutWireSphere(9.0f, 20, 20);
glPopMatrix();
glPopMatrix();
//glutWireCube(10.0f);

//Saturn orbita
glRotatef(-85, 0, 1, 2);
glPushMatrix();
glColor3f(0, 0, 1);
for (float angle = 0.0f; angle <= (2.0f*3.14159f)*1.0f; angle += 0.001f)
{
glBegin(GL_POINTS);
x1 = 50.0f*sin(angle);
z1 = 50.0f*cos(angle);
glVertex3f(x1, y1, z1);
glEnd();
}
glPopMatrix();

//Saturn
glColor3f(2.0f, 1.0f, 1.0f);
glPushMatrix();
x1 = 50.0f*sin(angle6);
z1 = 50.0f*cos(angle6);
glTranslatef(x1, y1, z1);
glRotatef(alfa6, x1, y1, z1);
glutWireSphere(9.0f, 20, 20);
glPopMatrix();
glPopMatrix();
//glutWireCube(10.0f);

glPushMatrix();
//orbita Uran
glRotatef(0, 0, 1, 4);
glPushMatrix();
glColor3f(0, 0, 1);
for (float angle = 0.0f; angle <= (2.0f*3.14159f)*1.0f; angle += 0.001f)
{
glBegin(GL_POINTS);
x1 = 60.0f*sin(angle);
z1 = 60.0f*cos(angle);
glVertex3f(x1, y1, z1);
glEnd();
}
glPopMatrix();
>>
//Uran
glColor3f(15.0f, 0.0f, 3.0f);
glPushMatrix();
x1 = 60.0f*sin(angle4);
z1 = 60.0f*cos(angle4);
glTranslatef(x1, y1, z1);
glRotatef(alfa4, x1, y1, z1);
glutWireSphere(7.0f, 20, 20);
glPopMatrix();
glPopMatrix();
//glutWireCube(10.0f);

glPushMatrix();
//orbita Pluton
glRotatef(0, 0, 1, 4);
glPushMatrix();
glColor3f(0, 0, 1);
for (float angle = 0.0f; angle <= (2.0f*3.14159f)*1.0f; angle += 0.001f)
{
glBegin(GL_POINTS);
x1 = 70.0f*sin(angle);
z1 = 70.0f*cos(angle);
glVertex3f(x1, y1, z1);
glEnd();
}
glPopMatrix();

//Pluton
glColor3f(15.0f, 0.0f, 3.0f);
glPushMatrix();
x1 = 70.0f*sin(angle4);
z1 = 70.0f*cos(angle4);
glTranslatef(x1, y1, z1);
glRotatef(alfa4, x1, y1, z1);
glutWireSphere(7.0f, 20, 20);
glPopMatrix();
glPopMatrix();
//glutWireCube(10.0f);

}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glpApplyCameraTransform(&frameCamera);

if (iCull)
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
if (iDepth)
glEnable(GL_DEPTH_TEST);
else
glDisable(GL_DEPTH_TEST);

if (iOutline)
glPolygonMode(GL_FRONT, GL_LINE);
else
glPolygonMode(GL_FRONT, GL_FILL);

glPushMatrix();
//Podloga();
glPushMatrix();
Rys_aktorow(0);
glPopMatrix();
glPopMatrix();

glFlush();
glutSwapBuffers();
}
>>
void Reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLdouble aspect = 1;
GLdouble blisko = 1.0;
GLdouble daleko = 200.0;
if (rzut == PERSP)
{
if (height>0)
aspect = width / (GLdouble)height;
gluPerspective(fory, aspect, blisko, daleko);
}
glutPostRedisplay();
}
void Keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case '1':
alfa1 -= 5.0f;
break;
case '2':
alfa2 += 5.0f;
break;
case '3':
alfa3 += 5.0f;
break;
case '4':
alfa4 += 5.0f;
break;
case '5':
alfa4 -= 5.0f;
break;
case '6':
alfa3 -= 5.0f;
break;
case '7':
alfa2 -= 5.0f;
break;
case '8':
alfa1 += 5.0f;
break;
case 'l':
xx += 1.0f;
break;
case 'r':
xx -= 1.0f;
break;
case 'u':
yy += 1.0f;
break;
case 'd':
yy -= 1.0f;
break;
case 'b':
zz += 1.0f;
break;
case 'f':
zz -= 1.0f;
break;
}
glutPostRedisplay();

}
>>
void SpecialKeys(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_LEFT:
glpRotateFrameLocalY(&frameCamera, 0.1);
break;
case GLUT_KEY_RIGHT:
glpRotateFrameLocalY(&frameCamera, -0.1);
break;
case GLUT_KEY_UP:
glpMoveFrameForward(&frameCamera, 0.1f);
break;
case GLUT_KEY_DOWN:
glpMoveFrameForward(&frameCamera, -0.1f);
break;
case GLUT_KEY_PAGE_UP:
glpMoveFrameUp(&frameCamera, 0.1f);
break;
case GLUT_KEY_PAGE_DOWN:
glpMoveFrameUp(&frameCamera, -0.1f);
break;
}

glutPostRedisplay();

}
//wywołannie w czasie bezczynności
void TimerFunction(int value)
{
glutPostRedisplay();
glutTimerFunc(3, TimerFunction, 1);
}

void Menu(int value)
{
switch (value)

{
case 10:
iDepth = !iDepth;
break;
case 20:
iCull = !iCull;
break;
case 30:
iOutline = !iOutline;
break;

case EXIT:
exit(0);
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Laboratorium 1");
glutReshapeFunc(Reshape);
glutDisplayFunc(Display);
glutKeyboardFunc(Keyboard);
glutSpecialFunc(SpecialKeys);
Ustawienia();
int MenuWyswietlania = glutCreateMenu(Menu);
glutAddMenuEntry("Testowanie glebi", 10);
glutAddMenuEntry("UKrywanie powierzchni niewidocznej", 20);
glutAddMenuEntry("Rysownanie szkieletu", 30);
//utworzenie menu podręcznego
glutCreateMenu(Menu);
glutAddSubMenu("Wyświetlanie", MenuWyswietlania);
glutAddMenuEntry("Wyjscie", EXIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutTimerFunc(3, TimerFunction, 1);
glutMainLoop();
Wyjscie();
return 0;
}
>>
Forgot to mention I used Nupengl packages in the process
Thread replies: 9
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.