Sign in to follow this  
ishkabible

OpenGL scaling down my Icosahedron

Recommended Posts

ishkabible    100
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.
 
#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;
}


Share this post


Link to post
Share on other sites
szecs    2990
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

Share this post


Link to post
Share on other sites
ishkabible    100
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.

Share this post


Link to post
Share on other sites
ishkabible    100
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



#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.

Share this post


Link to post
Share on other sites
Lord_Evil    680
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

  • Popular Now