• ### Announcements

• #### Wondering what's new and changed at GameDev.net?06/20/17

Check out the latest Staff Blog update that talks about what's changed, what's new, and what's up with these "Pixels".
Followers 0

# OpenGL Golden Rectangle!

## 6 posts in this topic

Hello guys.I need help.Really.. I have homework about golden rectangle.I didn't know anything about this homework.If i won't do this i won't pass this lesson just help me please.

I need golden rectangle codes in opengl

I ATTACHED MY HOMEWORK
Edited by sweeneyt0dd
-1

##### Share on other sites

Forum rules are quite clear about homework: Its your job to do it! We may help, but we don't solve it for you. So ... what is your problem in detail? Understanding the golden ratio? Understanding the assignment text? Knowledge of OpenGL? Knowledge of GLUT?

(Is this sentence complete?) What have you done / tried so far?

0

##### Share on other sites

Forum rules are quite clear about homework: Its your job to do it! We may help, but we don't solve it for you. So ... what is your problem in detail? Understanding the golden ratio? Understanding the assignment text? Knowledge of OpenGL? Knowledge of GLUT?

(Is this sentence complete?) What have you done / tried so far?

dude..I'm new in this lesson in class.Just want golden rectangle codes likes

#include "stdafx.h"
#include <glut.h>
#include <math.h>

GLfloat G = (1 + (sqrt(float (5))))/2;

GLfloat gla1 = 0;
GLfloat glb1 = 0;
GLfloat gla2;
GLfloat glb2;

bool flip = true;

void genNextRect(void)
{
if (flip == false)
{
gla2 = gla2;
glb2 = gla2/G;

}
else
{
glb2 = glb2;
gla2 = gla2/G;

}
}

void init(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0, 600.0, 0.0, 400.0, -15.0, 15.0);

glMatrixMode(GL_MODELVIEW);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(4.0);

gla2 = glutGet(GLUT_WINDOW_WIDTH) - 10;
glb2 = glutGet(GLUT_WINDOW_HEIGHT) - 10;

glBegin(GL_LINE_LOOP);
glColor3f(0, 0, 1);
glVertex3f(gla1, glb1, 0);
glVertex3f(gla1, glb2, 0);
glVertex3f(gla2, glb2, 0);
glVertex3f(gla2, glb1, 0);
glEnd();
glutSwapBuffers();
}

void myReshape(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, w, 0.0, h);
}

int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(50, 50);
glutInitWindowSize(600, 500);
glutCreateWindow("");
glutDisplayFunc(display);
glutReshapeFunc(myReshape);
init();
glutMainLoop();

}
0

##### Share on other sites

If i won't do this i won't pass this lesson just help me please.

... >_>

At this rate, how do you expect to complete the course?
1

##### Share on other sites

If i won't do this i won't pass this lesson just help me please.

... >_>

At this rate, how do you expect to complete the course?

You are right what u want to say.But you don't know why i don't understand nothing this lesson.I didn't go lessons because my family problems. I'm sorry buti just want a help thats all

0

##### Share on other sites
Okay, don't panic. It's simpler than it looks. Looking at [tt]genNextRect[/tt], it takes the width and height of a rectangle as global parameters, [tt]gla2[/tt] and [tt]glb2[/tt], and sets them to the next smallest golden rectangle. Note, [tt]genNextRect[/tt] assumes the [tt]gla2[/tt] and [tt]glb[/tt] are already a golden rectangle. This is done by taking one of the dimensions and dividing by the golden ratio, which will result in a smaller length. The [tt]flip[/tt] flag determine which dimension to shorten. It is the side with the longest length that is shortened. You will need to keep track of [tt]flip[/tt] such that, when [tt]genNextRect[/tt] is called, that the longest length of the rectangle is shortened. Alternatively, you could remove [tt]flip[/tt] entirely and change the condition in [tt]genNextRect[/tt] to select the longer edge. You may want to check that your rectangle's aspect ratio matches (or is close enough to) the golden ratio after calling [tt]genNextRect[/tt].

After you have called [tt]genNextRect[/tt] you will need to draw it as demonstrated in the [tt]glBegin[/tt]/[tt]glEnd[/tt] block in [tt]display[/tt]. The assignment requires you continue drawing rectangles until the rectangles are too small to display. So, all that's left to complete the assignment is finding the first golden rectangle in the screen and a loop that calls [tt]genNextRect[/tt] and draws the new rectangle until the rectangle is too small to display.

P.S.
Don't panic.
[spoiler]
In pseudo-code, it'd look something like this:
display:
let rectangle be the size of the screen

begin drawing lines
while (area of rectangle) > 1 pixel:
rectangle = genNextRect rectangle

set rectangle color
draw each rectangle edge

end drawing lines

[/spoiler] Edited by fastcall22
0

##### Share on other sites

Okay, don't panic. It's simpler than it looks. Looking at [tt]genNextRect[/tt], it takes the width and height of a rectangle as global parameters, [tt]gla2[/tt] and [tt]glb2[/tt], and sets them to the next smallest golden rectangle. Note, [tt]genNextRect[/tt] assumes the [tt]gla2[/tt] and [tt]glb[/tt] are already a golden rectangle. This is done by taking one of the dimensions and dividing by the golden ratio, which will result in a smaller length. The [tt]flip[/tt] flag determine which dimension to shorten. It is the side with the longest length that is shortened. You will need to keep track of [tt]flip[/tt] such that, when [tt]genNextRect[/tt] is called, that the longest length of the rectangle is shortened. Alternatively, you could remove [tt]flip[/tt] entirely and change the condition in [tt]genNextRect[/tt] to select the longer edge. You may want to check that your rectangle's aspect ratio matches (or is close enough to) the golden ratio after calling [tt]genNextRect[/tt].

After you have called [tt]genNextRect[/tt] you will need to draw it as demonstrated in the [tt]glBegin[/tt]/[tt]glEnd[/tt] block in [tt]display[/tt]. The assignment requires you continue drawing rectangles until the rectangles are too small to display. So, all that's left to complete the assignment is finding the first golden rectangle in the screen and a loop that calls [tt]genNextRect[/tt] and draws the new rectangle until the rectangle is too small to display.

P.S.
Don't panic.
[spoiler]
In pseudo-code, it'd look something like this:

display:
let rectangle be the size of the screen

begin drawing lines
while (area of rectangle) > 1 pixel:
rectangle = genNextRect rectangle

set rectangle color
draw each rectangle edge

end drawing lines

[/spoiler]

thank you very much. I will do this with your help :)

0

## Create an account

Register a new account

Followers 0

• ## Game Jobs

• ### Similar Content

• Hi guys,
I would like to contribute to a game project as a developer (open source possibly). I have some experiences in C/C++ in game development (perso projects). I don't know either unreal or unity but I have some knowledges in opengl, glsl and shading theory as I had some courses at university regarding to that. I have some knowledges in maths and basic in physics. I know a little how to use blender to do modelling, texturing and simple game assets (no characters, no animation no skinning/rigging). I have no game preferences but I like aventure game, dungeon crawler, platformers, randomly generated things. I know these kind of projects involve a lot of time and I'd be really to work on it but if there are no cleary defined specific design goals/stories/gameplay mechanics I would like to not be part of it x) and I would rather prefer a smaller but well defined project to work on that a huge and not 'finishable' one.
CircleOfLight97

• Hi, I finally released KILL COMMANDO on gamejolt for free. It is a retro-funsplatter-shooter with C64 style. Give it a try.

• void TimerFunction(int value) {  glutPostRedisplay();  glutTimerFunc(1000, TimerFunction, 1); } void drawScene() {  glClear(GL_COLOR_BUFFER_BIT);      drawScene_bug();  TimerFunction(1);  eraseScene_bug(); // drawScene_bug_two(); // eraseScene_bug_two(); drawScene_ship(); drawScene_bullet();  glutSwapBuffers(); }