aavash
aavash
Submitted By:
Aavash Adhikari (1)
CE-21 (3rd Year/ 2nd Semester)
Submitted To:
Dhiraj Shrestha
Department of Computer Science and Engineering
Q.2) Write the code snippets for setting graphics environment in your chosen
graphics library and display the resolution of your display system through
functions/classes provided by your graphics library
To set up the graphics environment, the required packages were installed through the
command-line using pip, Python's package management system.
pip install pygame PyOpenGL glfw
For resolution of the display system, the following code snippet uses the functions from the
glfw package:
def display_resolution(window):
width, height = glfwGetFramebufferSize(window)
print(f"Display resolution: {width}x{height}")
def main():
if not glfwInit():
return
window = glfwCreateWindow(750, 750, "Display window size", None, None)
if not window:
glfwTerminate()
return
glfwMakeContextCurrent(window)
display_resolution(window)
glfwSwapBuffers(window)
glfwTerminate()
if __name__ == "__main__":
main()
Q.3) Logo design
Source Code:
def draw():
glClearColor(1, 1, 1, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glBegin(GL_TRIANGLE_STRIP)
glColor3f(1, 0, 0)
glVertex2f(-0.2, 0)
glVertex2f(-0.2, 0.4)
glVertex2f(-0.1, 0)
glVertex2f(-0.1, 0.4)
glEnd()
glBegin(GL_TRIANGLE_STRIP)
glColor3f(1, 0, 0)
glVertex2f(0.1, 0)
glVertex2f(0.1, 0.4)
glVertex2f(0.2, 0)
glVertex2f(0.2, 0.4)
glEnd()
glBegin(GL_TRIANGLE_STRIP)
glColor3f(1, 0, 0)
glVertex2f(0.1, 0)
glVertex2f(-0.2, 0.4)
glVertex2f(0.2, 0)
glVertex2f(-0.1, 0.4)
glEnd()
glBegin(GL_TRIANGLE_STRIP)
glColor3f(1, 0, 0)
glVertex2f(0.445, 0.135)
glVertex2f(-0.445, 0.135)
glVertex2f(0.445, 0.265)
glVertex2f(-0.445, 0.265)
glEnd()
glFlush()
glBegin(GL_TRIANGLE_STRIP)
glColor3f(1, 1, 1)
glVertex2f(0.45, 0.26)
glVertex2f(0.2, 0.26)
glVertex2f(0.45, 0.38)
glVertex2f(0.2, 0.38)
glEnd()
glBegin(GL_TRIANGLE_STRIP)
glColor3f(1, 1, 1)
glVertex2f(-0.45, 0.14)
glVertex2f(-0.2, 0.14)
glVertex2f(-0.45, 0.02)
glVertex2f(-0.2, 0.02)
glEnd()
def main():
if not glfwInit():
return
window = glfwCreateWindow(750, 750, “Logo", None, None)
if not window:
glfwTerminate()
return
glfwMakeContextCurrent(window)
gluOrtho2D(-1, 1, -1, 1)
glfwSwapInterval(1)
while not glfwWindowShouldClose(window):
glfwPollEvents()
draw()
glfwSwapBuffers(window)
glfwTerminate()
if __name__ == "__main__":
main()
Resultt: