#include <windows.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
const GLfloat G_RATIO = (1 - sqrt(5))/2;
GLfloat rx;
GLfloat ry;
GLfloat rz;
int i;
int j;
int k;
const GLfloat P1[] = {0.0f, 1.0f, G_RATIO};
const GLfloat P2[] = {0.0f,-1.0f, G_RATIO};
const GLfloat P3[] = { 0.0f,-1.0f, -G_RATIO};
const GLfloat P4[] = {0.0f, 1.0f, -G_RATIO};
const GLfloat P5[] = {1.0f,G_RATIO, 0.0f};
const GLfloat P6[] = { -1.0f,G_RATIO, 0.0f};
const GLfloat P7[] = { -1.0f, -G_RATIO, 0.0f};
const GLfloat P8[] = {1.0f,-G_RATIO, 0.0f};
const GLfloat P9[] = { G_RATIO,0.0f, 1.0f};
const GLfloat P10[] = { -G_RATIO, 0.0f, 1.0f};
const GLfloat P11[] = {-G_RATIO,0.0f, - 1.0f};
const GLfloat P12[] = { G_RATIO,0.0f, -1.0f};
const GLfloat purple[] = { 1.0f,0.0f,1.0f,0.4f};
const GLfloat green[] = { 0.0f,1.0f,0.0f,0.4f};
const GLfloat blue[] = { 0.0f,0.0f,1.0f,0.4f};
const GLfloat red[] = {1.0f,0.0f,0.0f,1.0f};
const GLfloat org[] = {1.0f,1.0f,0.0f,1.0f};
GLfloat r;
GLfloat theta;
GLfloat Asm;
GLfloat RP1[3];
GLfloat RP2[3];
GLfloat RP3[3];
GLfloat RP4[3];
GLfloat RP5[3];
GLfloat RP6[3];
GLfloat RP7[3];
GLfloat RP8[3];
GLfloat RP9[3];
GLfloat RP10[3];
GLfloat RP11[3];
GLfloat RP12[3];
char *one;
char *two;
char *three;
char *four;
char *five;
char *six;
char *seven;
char *eight;
char *nine;
char *ten;
char *eleven;
char *twelve;
static void resize(int width, int height) {
const float ar = (float) width / (float) height;
glDisable(GL_CULL_FACE);
glDepthFunc(GL_EQUAL);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0, 0, width, height);
glEnable(GL_LIGHT1);
glClearColor(1,1,1,1);
glMatrixMode(GL_PROJECTION);
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
static void display(void) {
one = "1";
two = "2";
three = "3";
four = "4";
five = "5";
six = "6";
seven = "7";
eight = "8";
nine = "9";
ten = "t";
eleven = "e";
twelve = "w";
r = sqrt(pow(P1[0],2)+pow(P1[1],2)+ pow(P1[2],2));
theta = acos(((P1[2])/(sqrt(pow(P1[0],2)+pow(P1[1],2)+ pow(P1[2],2)))));
Asm = atan2(P1[0],P1[1]);
r = r/2;
RP1[0] = r*sin(theta)*cos(Asm);
RP1[1] = r*sin(theta)*cos(Asm);
RP1[2] = r*cos(theta);
r = sqrt(pow(P2[0],2)+pow(P2[1],2)+ pow(P2[2],2));
theta = acos(((P2[2])/(sqrt(pow(P2[0],2)+pow(P2[1],2)+ pow(P2[2],2)))));
Asm = atan2(P2[0],P2[1]);
r = r/2;
RP2[0] = r*sin(theta)*cos(Asm);
RP2[1] = r*sin(theta)*cos(Asm);
RP2[2] = r*cos(theta);
r = sqrt(pow(P1[0],2)+pow(P3[1],2)+ pow(P3[2],2));
theta = acos(((P3[2])/(sqrt(pow(P3[0],2)+pow(P3[1],2)+ pow(P3[2],2)))));
Asm = atan2(P3[0],P3[1]);
r = r/2;
RP3[0] = r*sin(theta)*cos(Asm);
RP3[1] = r*sin(theta)*cos(Asm);
RP3[2] = r*cos(theta);
r = sqrt(pow(P4[0],2)+pow(P4[1],2)+ pow(P4[2],2));
theta = acos(((P4[2])/(sqrt(pow(P4[0],2)+pow(P4[1],2)+ pow(P4[2],2)))));
Asm = atan2(P4[0],P4[1]);
r = r/2;
RP4[0] = r*sin(theta)*cos(Asm);
RP4[1] = r*sin(theta)*cos(Asm);
RP4[2] = r*cos(theta);
r = sqrt(pow(P5[0],2)+pow(P5[1],2)+ pow(P5[2],2));
theta = acos(((P5[2])/(sqrt(pow(P5[0],2)+pow(P5[1],2)+ pow(P5[2],2)))));
Asm = atan2(P5[0],P5[1]);
r = r/2;
RP5[0] = r*sin(theta)*cos(Asm);
RP5[1] = r*sin(theta)*cos(Asm);
RP5[2] = r*cos(theta);
r = sqrt(pow(P7[0],2)+pow(P7[1],2)+ pow(P7[2],2));
theta = acos(((P7[2])/(sqrt(pow(P7[0],2)+pow(P7[1],2)+ pow(P7[2],2)))));
Asm = atan2(P7[0],P7[1]);
r = r/2;
RP7[0] = r*sin(theta)*cos(Asm);
RP7[1] = r*sin(theta)*cos(Asm);
RP7[2] = r*cos(theta);
r = sqrt(pow(P6[0],2)+pow(P6[1],2)+ pow(P6[2],2));
theta = acos(((P6[2])/(sqrt(pow(P6[0],2)+pow(P6[1],2)+ pow(P6[2],2)))));
Asm = atan2(P6[0],P6[1]);
r = r/2;
RP6[0] = r*sin(theta)*cos(Asm);
RP6[1] = r*sin(theta)*cos(Asm);
RP6[2] = r*cos(theta);
r = sqrt(pow(P9[0],2)+pow(P9[1],2)+ pow(P9[2],2));
theta = acos(((P9[2])/(sqrt(pow(P9[0],2)+pow(P9[1],2)+ pow(P9[2],2)))));
Asm = atan2(P9[0],P9[1]);
r = r/2;
RP9[0] = r*sin(theta)*cos(Asm);
RP9[1] = r*sin(theta)*cos(Asm);
RP9[2] = r*cos(theta);
r = sqrt(pow(P10[0],2)+pow(P10[1],2)+ pow(P10[2],2));
theta = acos(((P10[2])/(sqrt(pow(P10[0],2)+pow(P10[1],2)+ pow(P10[2],2)))));
Asm = atan2(P10[0],P10[1]);
r = r/2;
RP10[0] = r*sin(theta)*cos(Asm);
RP10[1] = r*sin(theta)*cos(Asm);
RP10[2] = r*cos(theta);
r = sqrt(pow(P11[0],2)+pow(P11[1],2)+ pow(P11[2],2));
theta = acos(((P11[2])/(sqrt(pow(P11[0],2)+pow(P11[1],2)+ pow(P11[2],2)))));
Asm = atan2(P11[0],P11[1]);
r = r/2;
RP11[0] = r*sin(theta)*cos(Asm);
RP11[1] = r*sin(theta)*cos(Asm);
RP11[2] = r*cos(theta);
r = sqrt(pow(P12[0],2)+pow(P12[1],2)+ pow(P12[2],2));
theta = acos(((P12[2])/(sqrt(pow(P12[0],2)+pow(P12[1],2)+ pow(P12[2],2)))));
Asm = atan2(P12[0],P12[1]);
r = r/2;
RP12[0] = r*sin(theta)*cos(Asm);
RP12[1] = r*sin(theta)*cos(Asm);
RP12[2] = r*cos(theta);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(ry,1.0f,0.0f,0.0f);
glRotatef(rx,0.0f,1.0f,0.0f);
glRotatef(rz,0.0f,0.0f,1.0f);
glBegin(GL_TRIANGLES);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P1); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P4); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P7);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P1); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P4); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P8);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P1); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P11); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P12);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P4); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P9); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P10);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P4); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P9); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P7);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P1); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P11); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P8);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P1); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P12); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P7);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P4); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P10); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P8);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P8); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P5); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P10);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P8); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P11); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P5);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P7); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P12); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P6);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P7); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P9); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P6);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P12); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P11); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P2);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P12); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P2); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P6);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P9); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P10); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P3);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P11); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P5); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P2);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P5); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P10); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P3);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P5); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P2); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P3);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P9); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P6); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P3);
glColor4fv(blue); // Set Top Point Of Triangle To Red
glVertex3fv( P2); // First Point Of The Triangle
glColor4fv(green); // Set Left Point Of Triangle To Green
glVertex3fv(P6); // Second Point Of The Triangle
glColor4fv(purple); // Set Right Point Of Triangle To Blue
glVertex3fv( P3);
glEnd();
glColor4f(0.0f,0.0f,0.0f,1.0f);
glRasterPos3fv(P1);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *one);
glRasterPos3fv(P2);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *two);
glRasterPos3fv(P3);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *three);
glRasterPos3fv(P4);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *four);
glRasterPos3fv(P5);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *five);
glRasterPos3fv(P6);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *six);
glRasterPos3fv(P7);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *seven);
glRasterPos3fv(P8);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eight);
glRasterPos3fv(P9);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *nine);
glRasterPos3fv(P10);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *ten);
glRasterPos3fv(P11);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eleven);
glRasterPos3fv(P12);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *twelve);
glRasterPos3fv(RP1);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *one);
glRasterPos3fv(RP2);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *two);
glRasterPos3fv(RP3);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *three);
glRasterPos3fv(RP4);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *four);
glRasterPos3fv(RP5);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *five);
glRasterPos3fv(RP6);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *six);
glRasterPos3fv(RP7);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *seven);
glRasterPos3fv(RP8);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eight);
glRasterPos3fv(RP9);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *nine);
glRasterPos3fv(RP10);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *ten);
glRasterPos3fv(RP11);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eleven);
glRasterPos3fv(RP12);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *twelve);
glutSwapBuffers();
}
static void key(unsigned char key, int x, int y) {
switch (key) {
case 'd':
rx +=3.0f;
break;
case 'a':
rx -=3.0f;
break;
case 'w':
ry +=3.0f;
break;
case 's':
ry -=3.0f;
break;
case 'z':
rz +=3.0f;
break;
case 'x':
rz -=3.0f;
break;
}
glutPostRedisplay();
}
static void idle(void) {
glutPostRedisplay();
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glutMainLoop();
return 1;
}
scaling down my Icosahedron
OK this one is more of a math problem that it is anything else but it dose pertain to OpenGL so i thought i would post it here due to higher activity. OK so look where i populated the RP1-12 arrays. i was trying to convert Cartesian to Sphere and then back again but with modified Radius so it would be closer to the origin. but for some reason they all just ended up being Coplanar (well i don't know that but it looks that way. if there not there very close). so i was hoping someone could point out my error.
So do you want to scale your icosahedron?
(BTW you could do all this in one thread, there's no need to flood the forum with so closely related threads)
Anyway:
When do you want to do the scaling? Only once at startup or something? It would be easier to make an init or create function for the icosahedron, where you assign values to the vertices. You could use size instead of 1.0, and size*G_RATIO
(BTW you could do all this in one thread, there's no need to flood the forum with so closely related threads)
Anyway:
When do you want to do the scaling? Only once at startup or something? It would be easier to make an init or create function for the icosahedron, where you assign values to the vertices. You could use size instead of 1.0, and size*G_RATIO
well i want to scale down the distance from the origin to each vortices's individually. so that the "scaled version" would be irregular so one Size variable will not do but many might do very well. also i want to make the scaled version exist with in the regular version. i will try the Size and Size*G_Ratio thing and go from there, thanks.
thank you it worked perfectly i'm almost done with what i was doing and will remember to not "flood" forums next time i have something like this to do.
OK so now i want my text to not display when it goes behind the shape and also i want to be able to display multiple charters in one spot so the "12" is not just "1" and "1" and then "2" is not just a 1 over a two. i looked on google but cant find anything.
here is my current code
also on a side note, i need to make this program compatible with Macintosh as my school's computers are all Macintosh. so some help with that would be nice, i think it is something simple with header files right.
here is my current code
#include <windows.h>#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>#include <stdlib.h>#include <stdio.h>#include <cmath>const GLfloat G_RATIO = (1 - sqrt(5))/2;GLfloat rx;GLfloat ry;GLfloat rz;GLfloat size;int i;int j;int k;const GLfloat P1[] = {0.0f, 1.0f, G_RATIO};const GLfloat P2[] = {0.0f,-1.0f, G_RATIO};const GLfloat P3[] = { 0.0f,-1.0f, -G_RATIO};const GLfloat P4[] = {0.0f, 1.0f, -G_RATIO};const GLfloat P5[] = {1.0f,G_RATIO, 0.0f};const GLfloat P6[] = { -1.0f,G_RATIO, 0.0f};const GLfloat P7[] = { -1.0f, -G_RATIO, 0.0f};const GLfloat P8[] = {1.0f,-G_RATIO, 0.0f};const GLfloat P9[] = { G_RATIO,0.0f, 1.0f};const GLfloat P10[] = { -G_RATIO, 0.0f, 1.0f};const GLfloat P11[] = {-G_RATIO,0.0f, - 1.0f};const GLfloat P12[] = { G_RATIO,0.0f, -1.0f};const GLfloat purple[] = { 1.0f,0.0f,1.0f,0.4f};const GLfloat green[] = { 0.0f,1.0f,0.0f,0.4f};const GLfloat blue[] = { 0.0f,0.0f,1.0f,0.4f};const GLfloat red[] = {1.0f,0.0f,0.0f,1.0f};const GLfloat org[] = {1.0f,1.0f,0.0f,1.0f};const GLfloat yellow[] = {1.0f,0.0f,1.0f,1.0f}; GLfloat RP1[3]; GLfloat RP2[3]; GLfloat RP3[3]; GLfloat RP4[3]; GLfloat RP5[3]; GLfloat RP6[3]; GLfloat RP7[3]; GLfloat RP8[3]; GLfloat RP9[3]; GLfloat RP10[3]; GLfloat RP11[3]; GLfloat RP12[3];char *one;char *two;char *three;char *four;char *five;char *six;char *seven;char *eight;char *nine;char *ten;char *eleven;char *twelve;static void resize(int width, int height) { const float ar = (float) width / (float) height; glDisable(GL_CULL_FACE); glDepthFunc(GL_EQUAL); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glViewport(0, 0, width, height); glEnable(GL_LIGHT1); glClearColor(1,1,1,1); glMatrixMode(GL_PROJECTION); glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity() ;}static void display(void) { one = "1"; two = "2"; three = "3"; four = "4"; five = "5"; six = "6"; seven = "7"; eight = "8"; nine = "9"; ten = "t"; eleven = "e"; twelve = "w"; size = 0.5f; RP1[0] = 0.0f; RP1[1] = size; RP1[2] = size*G_RATIO; size = 1.0f; RP2[0] = 0.0f; RP2[1] = -size; RP2[2] = size*G_RATIO; size = 0.7f; RP3[0] = 0.0f; RP3[1] = -size; RP3[2] = -size*G_RATIO; size = 0.3f; RP4[0] = 0.0f; RP4[1] = size; RP4[2] = -size*G_RATIO; size = 0.1f; RP5[0] = size; RP5[1] = size*G_RATIO; RP5[2] = 0.0f; size = 0.5f; RP6[0] = -size; RP6[1] = size*G_RATIO; RP6[2] = 0.0f; size = 0.8f; RP7[0] = -size; RP7[1] = -size*G_RATIO; RP7[2] = 0.0f; size = 0.2f; RP8[0] = size; RP8[1] = -size*G_RATIO; RP8[2] = 0.0f; size = 1.2f; RP9[0] = size*G_RATIO; RP9[1] = 0.0f; RP9[2] = size; size = 0.5f; RP10[0] = -size*G_RATIO; RP10[1] = 0.0f; RP10[2] = size; size = 0.9f; RP11[0] = -size*G_RATIO; RP11[1] = 0.0f; RP11[2] = -size; size = 0.4f; RP12[0] = size*G_RATIO; RP12[1] = 0.0f; RP12[2] = -size; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glRotatef(ry,1.0f,0.0f,0.0f); glRotatef(rx,0.0f,1.0f,0.0f); glRotatef(rz,0.0f,0.0f,1.0f); glBegin(GL_TRIANGLES); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P1); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P4); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P7); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P1); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P4); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P8); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P1); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P12); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P4); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P9); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P10); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P4); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P9); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P7); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P1); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P8); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P1); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P12); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P7); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P4); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P10); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P8); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P8); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P5); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P10); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P8); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P5); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P7); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P12); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P6); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P7); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P9); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P6); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P12); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P2); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P12); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P2); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P6); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P9); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P10); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P3); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P11); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P5); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P2); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P5); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P10); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P3); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P5); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P2); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P3); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P9); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P6); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P3); glColor4fv(blue); // Set Top Point Of Triangle To Red glVertex3fv( P2); // First Point Of The Triangle glColor4fv(green); // Set Left Point Of Triangle To Green glVertex3fv(P6); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( P3); // here the new one begines glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP1); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP4); // Second Point Of The Triangle glColor4fv(yellow); // Set Right Point Of Triangle To Blue glVertex3fv( RP7); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP1); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP4); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP8); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP1); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP12); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP4); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP9); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP10); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP4); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP9); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP7); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP1); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP8); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP1); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP12); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP7); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP4); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP10); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP8); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP8); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP5); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP10); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP8); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP5); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP7); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP12); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP6); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP7); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP9); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP6); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP12); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP11); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP2); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP12); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP2); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP6); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP9); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP10); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP3); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP11); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP5); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP2); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP5); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP10); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP3); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP5); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP2); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP3); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP9); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP6); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP3); glColor4fv(red); // Set Top Point Of Triangle To Red glVertex3fv( RP2); // First Point Of The Triangle glColor4fv(org); // Set Left Point Of Triangle To Green glVertex3fv(RP6); // Second Point Of The Triangle glColor4fv(purple); // Set Right Point Of Triangle To Blue glVertex3fv( RP3); glEnd(); glColor4f(0.0f,0.0f,0.0f,1.0f); glRasterPos3fv(P1); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *one); glRasterPos3fv(P2); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *two); glRasterPos3fv(P3); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *three); glRasterPos3fv(P4); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *four); glRasterPos3fv(P5); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *five); glRasterPos3fv(P6); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *six); glRasterPos3fv(P7); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *seven); glRasterPos3fv(P8); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eight); glRasterPos3fv(P9); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *nine); glRasterPos3fv(P10); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *ten); glRasterPos3fv(P11); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eleven); glRasterPos3fv(P12); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *twelve); glRasterPos3fv(RP1); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *one); glRasterPos3fv(RP2); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *two); glRasterPos3fv(RP3); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *three); glRasterPos3fv(RP4); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *four); glRasterPos3fv(RP5); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *five); glRasterPos3fv(RP6); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *six); glRasterPos3fv(RP7); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *seven); glRasterPos3fv(RP8); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eight); glRasterPos3fv(RP9); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *nine); glRasterPos3fv(RP10); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *ten); glRasterPos3fv(RP11); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eleven); glRasterPos3fv(RP12); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *twelve); glutSwapBuffers();}static void key(unsigned char key, int x, int y) { switch (key) { case 'd': rx +=3.0f; break; case 'a': rx -=3.0f; break; case 'w': ry +=3.0f; break; case 's': ry -=3.0f; break; case 'z': rz +=3.0f; break; case 'x': rz -=3.0f; break; } glutPostRedisplay();}static void idle(void) { glutPostRedisplay();}int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(640,480); glutInitWindowPosition(10,10); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("GLUT Shapes"); glutReshapeFunc(resize); glutDisplayFunc(display); glutKeyboardFunc(key); glutIdleFunc(idle); glutMainLoop(); return 1;}
also on a side note, i need to make this program compatible with Macintosh as my school's computers are all Macintosh. so some help with that would be nice, i think it is something simple with header files right.
You're currently doing pure 2D rendering of the text, i.e. without depth information. What you need is to place the text in the 3D world in order to make your object hide the text if it is behind the object.
Basically, you would render textured billboards that display your text, either with one billboard per character or one billboard using a texture that contains the whole text (e.g. a "12" texture). You would then calculate some point next to the vertex (you're numbering the vertices, right?), e.g. by adding some x*normal to the vertex position.
There are plenty of tutorials on texture mapped font rendering and billboarding.
For a start look here and here
Basically, you would render textured billboards that display your text, either with one billboard per character or one billboard using a texture that contains the whole text (e.g. a "12" texture). You would then calculate some point next to the vertex (you're numbering the vertices, right?), e.g. by adding some x*normal to the vertex position.
There are plenty of tutorials on texture mapped font rendering and billboarding.
For a start look here and here
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement