by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Similar documents
Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

COMPUTER GRAPHICS LAB # 3

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Basic Graphics Programming

Announcements OpenGL. Computer Graphics. Spring CS4815

6. Make use of glviewport() to display two sine curves on the same screen, one on the

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Andrew Yenalavitch Homework 1 CSE Fall 2014


Introduction to OpenGL: Part 2

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Lecture 3. Understanding of OPenGL programming

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

CS 432 Interactive Computer Graphics

Drawing Primitives. OpenGL basics

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Assignment 1. Simple Graphics program using OpenGL

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Basic Graphics Programming

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Programming with OpenGL Part 3: Three Dimensions

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Introduction to Computer Graphics with OpenGL/GLUT

Computer Graphics, Chapt 08

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Graphics Programming

Computer Graphics. OpenGL

Computer graphics MN1

Computer Graphics: Line Drawing Algorithms

Display Lists in OpenGL

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

Precept 2 Aleksey Boyko February 18, 2011

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

Using OpenGL with CUDA

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Lectures OpenGL Introduction

CSE4030 Introduction to Computer Graphics

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

CS621 Lab 1 Name: Ihab Zbib

Bob s Concise Introduction to Doxygen

PART-I: Lab for MCS-051 (Advanced Internet Technologies)

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Lecture 4 of 41. Lab 1a: OpenGL Basics

2 Transformations and Homogeneous Coordinates

Overview of Graphics Systems Hearn & Baker Chapter 2. Some slides are taken from Robert Thomsons notes.

Computer Graphics (Basic OpenGL)

Programming using OpenGL: A first Introduction

1/12/11. Basic Graphics Programming. What is OpenGL. OpenGL is cross-platform. How does OpenGL work. How does OpenGL work (continued) The result

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Programming with OpenGL Part 1: Background

LECTURE 02 OPENGL API

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

Computer Graphics Introduction to OpenGL

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

C OMPUTER G RAPHICS Thursday

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Installing and Running PyOpenGL (Windows)

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

OpenGL JOGL. OpenGL & JOGL. Shaoting Zhang, or Tony. September 12, 2007

Introduction to OpenGL

Computer Graphics 1 Computer Graphics 1

Source code: #include <iostream>

Interaction Computer Graphics I Lecture 3

Introduction to OpenGL

Computer graphics MN1

Computer Graphics. Bing-Yu Chen National Taiwan University

RECITATION - 1. Ceng477 Fall

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Introduction to MS Visual C/C++

Computer Graphics Primitive Attributes

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

OpenGL refresher. Advanced Computer Graphics 2012

VR-programming tools (procedural) More VRML later in this course! (declarative)

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

Lecture 2 2D transformations Introduction to OpenGL

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Introduction to OpenGL

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

1.2 Basic Graphics Programming

Interaction. CSCI 480 Computer Graphics Lecture 3

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Computer Graphics Course 2005

Transcription:

Zoe Veale Lab 2 Draw2 part 1: I edited the glutinitwindowsize() function tom change the size of my screen window. int main(int argc, char** argv) glutinit(&argc, argv); //initialize toolkit glutinitdisplaymode (GLUT_SINGLE GLUT_RGB ); //set display mode: single bufferring RGB model glutinitwindowsize(200, 300); //set window size on screen glutinitwindowposition( 200, 200 ); //set window position on screen glutcreatewindow(argv[0]); //open screen window // glutcreatewindow( "CS 420 Draw" ); //open screen window init(); glutdisplayfunc (display); //points to display function glutmainloop(); //go into perpetual loop return 0; by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Part 2: Similarly, by editing glutinitwindowposition() parameters you can move where the screen renders at, glutinitwindowposition(0,0) being the top left of the world window, but glutinitwindowposition(300, 350) being 300 pixels to the right (xaxis) and 350 pixels down (yaxis). int main(int argc, char** argv) glutinit(&argc, argv); //initialize toolkit glutinitdisplaymode (GLUT_SINGLE GLUT_RGB ); //set display mode: single bufferring RGB model glutinitwindowsize(500, 500); //set window size on screen glutinitwindowposition( 300, 350 ); //set window position on screen glutcreatewindow(argv[0]); //open screen window // glutcreatewindow( "CS 420 Draw" ); //open screen window init(); glutdisplayfunc (display); //points to display function glutmainloop(); //go into perpetual loop return 0; Further editing of the glutinitwindowpostion() function will change the position of the screen, even to move it off the world window entirely if the parameters are to high or in the negatives.

Part 3: Another function that can be edited for the users needs is gluortho2d(), it takes in two parameters that edit the display screen s (in the screen window) x and y axis. For example, gluortho2d(500, 500), means 500 pixels on the x-axis and 500 pixels o the y-axis. But, the bottom left of the screen window is considered to be (0,0). if you increase these values over 500 you will the the graphics that have been render to be shifted. void init( void ) glclearcolor( 1.0, 1.0, 1.0, 0.0 ); //get white background color glcolor3f( 0.0f, 1.0f, 0.0f ); //set drawing color glpointsize( 8.0 ); //a dot is 4x4 glmatrixmode( GL_PROJECTION ); glloadidentity(); //replace current matrix with identity matrix gluortho2d( 0.0, 1000.0, 0.0, 1000.0 );

part 4: continuing our editing of functions, in the top of our display function if we add, glviewport( ), it takes in 4 parameters that allows us to change where the rest of the display function is render. For example, adding: glviewport(150,200,250,100) shows: we basically make a window within our window we are rendering all of our primitives to. void display( void ) glviewport( 150, 200, 250, 100); //add a view port glclear( GL_COLOR_BUFFER_BIT ); //clear screen /* rest of code... */

Bresenham part: As discussed in class, I was able to implement the bresenham formula into my code thanks to the provided code. I edited it to make a Line() and Circle() function that each take in 4 parameters so I could draw more than one easily. void Draw() int x0, y0, xn, yn; int xcenter,ycenter,r; x0 = 0; y0 = 0; xn = 250; yn = 250; xcenter = 250; ycenter = 250; r = 20; glclear(gl_color_buffer_bit); //clear screen DrawLine(x0, y0, xn, yn); DrawCircle(xCenter, ycenter, r);

glflush(); void DrawLine(int x0, int y0, int xn, int yn) int x, y; int dx, dy, //deltas pk, //decision parameter k; //looping variable glcolor3f( 1,0, 0); setpixel(x0, y0); //plot first point // difference between starting and ending points dx = xn - x0; dy = yn - y0; pk = 2 * dy - dx; x = x0; y = y0; for ( k = 0; k < dx-1; ++k ) if ( pk < 0 ) pk = pk + 2 * dy; else pk = pk + 2*dy - 2*dx; ++y; ++x; setpixel( x, y ); //calculate next pk //next pixel: (x+1, y ) //next pixel: (x+1, y+1) //calculate next pk void DrawCircle(int xcenter, int ycenter, int r) int x, y; x=0; y=r; int d = 3/2 - r; // = 1 - r glcolor3f( 1,0, 0); while(x<=y) setpixel(xcenter+x,ycenter+y); setpixel(xcenter+y,ycenter+x); //find other points by symmetry setpixel(xcenter-x,ycenter+y); setpixel(xcenter+y,ycenter-x); setpixel(xcenter-x,ycenter-y);

setpixel(xcenter-y,ycenter-x); setpixel(xcenter+x,ycenter-y); setpixel(xcenter-y,ycenter+x); if (d<0) d += (2*x)+3; else d += (2*(x-y))+5; y -= 1; x++; I could also iterated through a loop while editing the parameters to make some interesting designs.

Summary: This lab helped me understand several of the functions that opengl and GLUT rely on to make the the library easy to use and understand. GlutInitWindowSize(), glutinitwindowposition(), gluortho2d(), and glviewport() are all powerful functions that are very simple in nature. Going over the Bresenham code following the lecture helped cement my understanding of how a pixel is filled in on the screen. And led to some interesting patters beign displayed on my screen window. After finishing every part of this lab and demonstrating my understanding of the code I believe I have earned full points on this lab.