CS 470 Homework 2: Interactive 2D Graphics Project, Assignments of Computer Graphics

A homework assignment for a cs 470 course focused on 2d interactive graphics using glut and opengl. Students are required to create an application with window management, opengl drawing, glut text, special keyboard and mouse callbacks, and keyboard input. The project includes rendering a player, target, and projectile, as well as implementing text and user input. Extra credit is given for adding additional objects and behaviors.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-896
koofers-user-896 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 470 Homework 2 : Due Sept. 5, 2008
1 2D Interactive Graphics
The goal of this homework is to learn to write GLUT callback functions for ren-
dering and user input, and to become familiar with OpenGL through basic 2D
rendering. You may use the files from homework 1 as a starting point. Refer to
http://www.opengl.org/documentation/specs/glut/spec3/spec3.html for
a full description of glut functions.
1.1 Specification
Your will create an interactive 2D application with the following features:
10% - Window management : Open a 480 ×480 window. The text in the
titlebar should read ’Homework 2’ followed by your last and first name.
10% - OpenGL drawing : The background color (use glClearColor)
should be white. Draw a grid of gray horizontal and vertical lines spaced
0.1 units apart. The grid lines through the origin should be 2 pixels wide,
all others should be 1 pixel wide. This grid background should appear
behind all other graphics. Use rendering order to achieve this (render
from back to front, do not use the depth buffer).
10% - OpenGL drawing : Render the ’player’ as a square polygon 0.5 units
wide using points and lines. Render the vertex points in blue, four pixels
wide. Render the edges of the polygon in green, with 2 pixel wide lines.
The player will move in response to keyboard input.
Also render a target as a red cross with a vertical and horizonal line, each
0.1 unit long. Initially the cross is at the origin (center of the screen). The
target will move in response to mouse input.
Render a projectile as a white point 5 pixels wide. Initially the player,
target, and projectile are all centered at the origin.
20% - GLUT text : Using the appropriate OpenGL functions and glut
bitmap text routines, write a function DrawText(float x, float y, float
z, void* font, char* text). Print the projectile coordinates in the
lower left corner. The text should appear on top of all other graph-
ics. Hint : glRasterPos2f and glutBitmapCharacter. Use the 24-point
proportional spaced Times Roman font.
1
pf2

Partial preview of the text

Download CS 470 Homework 2: Interactive 2D Graphics Project and more Assignments Computer Graphics in PDF only on Docsity!

CS 470 Homework 2 : Due Sept. 5, 2008

1 2D Interactive Graphics

The goal of this homework is to learn to write GLUT callback functions for ren- dering and user input, and to become familiar with OpenGL through basic 2D rendering. You may use the files from homework 1 as a starting point. Refer to http://www.opengl.org/documentation/specs/glut/spec3/spec3.html for a full description of glut functions.

1.1 Specification

Your will create an interactive 2D application with the following features:

  • 10% - Window management : Open a 480 × 480 window. The text in the titlebar should read ’Homework 2’ followed by your last and first name.
  • 10% - OpenGL drawing : The background color (use glClearColor) should be white. Draw a grid of gray horizontal and vertical lines spaced 0.1 units apart. The grid lines through the origin should be 2 pixels wide, all others should be 1 pixel wide. This grid background should appear behind all other graphics. Use rendering order to achieve this (render from back to front, do not use the depth buffer).
  • 10% - OpenGL drawing : Render the ’player’ as a square polygon 0.5 units wide using points and lines. Render the vertex points in blue, four pixels wide. Render the edges of the polygon in green, with 2 pixel wide lines. The player will move in response to keyboard input. Also render a target as a red cross with a vertical and horizonal line, each 0.1 unit long. Initially the cross is at the origin (center of the screen). The target will move in response to mouse input. Render a projectile as a white point 5 pixels wide. Initially the player, target, and projectile are all centered at the origin.
  • 20% - GLUT text : Using the appropriate OpenGL functions and glut bitmap text routines, write a function DrawText(float x, float y, float z, void* font, char* text). Print the projectile coordinates in the lower left corner. The text should appear on top of all other graph- ics. Hint : glRasterPos2f and glutBitmapCharacter. Use the 24-point proportional spaced Times Roman font.
  • 20% - Special keyboard callback : Pressing the arrow keys will trans- late the player 0.1 units in the corresponding direction. Look at the glutSpecialFunc documentation to find the macros defining each arrow key.
  • 15% - Mouse callback and animation: Pressing the left mouse button will set the projectile position to the player position and will also set the target position to the mouse position. The projectile should be given a velocity such that it will pass through the target. It is OK if the projectile continues past the target and moves off screen. This functionality will require writing code that maps points in mouse coordinates [0, 479] × [0, 479] to world coordinates [− 1 , 1] × [− 1 , 1]. Note that the origin of the mouse coordinate system is in the upper left corner of the window.
  • 10% - Keyboard callback : Pressing the ESC key should cause the pro- gram to exit. Pressing the space bar should reset the player, target and projectile to the origin.
  • 5% - Documentation : Create a README file with your name and a description of which features work correctly.

5% Extra credit: Add some other objects to the scene. Do something interesting (change color, animate) if the projectile hits that object. Be sure to note this behavior in README. Either full or zero credit will be given for each of these specifications.

2 What to turn in

Submit all source code, a README file, and a working project file or Makefile which builds an executable named ’hw2’ or ’hw2.exe’. Turn in a single tarred and gzipped, or zipped file by the start of class on the due date (ecampus or on CD).