RGBA
|
Component |
Name |
Meaning |
Range |
|
R |
Red |
Red component |
0 to 1 |
|
G |
Green |
Green component |
0 to 1 |
|
B |
Blue |
Blue component |
0 to 1 |
|
A |
Alpha* |
Transparency |
0 (complete) to 1 (none) |
*More on Alpha later
![]() |
![]() |
|
#include
"stdafx.h"
#include
<GL/glut.h>
void mydisplay() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glEnd();
glTranslatef(0.5f, 0.5f, 0.0f);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glEnd();
glFlush(); }
int main(int
argc, char** argv) {
glutCreateWindow("A Triangle");
glutDisplayFunc(mydisplay);
glutMainLoop(); } |
![]() |
|
#include
"stdafx.h"
// Microsoft's precompiled header
- required for Visual C++
#include
<gl/glut.h>
// also includes gl.h, glu.h
// Initialize
OpenGL Graphics
void
initGL()
{
// Set clearing color to black (for
filling the background)
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); }
// Handler for
window-paint event. Call back whenever window needs to be
re-painted.
void
display()
{
glClear(GL_COLOR_BUFFER_BIT);
// Clear the color buffer with
current clearing color
// Define shapes enclosed with a pair of
glBegin and glEnd
glBegin(GL_QUADS);
// Each set of 4 vertices form a
quad
glColor3f(1.0f, 0.0f, 0.0f);
// Red
glVertex2f(-0.8f, 0.1f);
// Define vertices in counter-clockwise
glVertex2f(-0.2f, 0.1f);
glVertex2f(-0.2f, 0.7f);
glVertex2f(-0.8f, 0.7f);
glColor3f(0.0f, 0.0f, 1.0f);
// Blue
glVertex2f(-0.7f, -0.6f);
glVertex2f(-0.1f, -0.6f);
glVertex2f(-0.1f,
0.0f);
glVertex2f(-0.7f,
0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
// White
glVertex2f(-0.9f, -0.7f);
glVertex2f(-0.5f, -0.7f);
glVertex2f(-0.5f, -0.3f);
glVertex2f(-0.9f, -0.3f);
glEnd();
glBegin(GL_TRIANGLES);
// Each set of 3 vertices form a
triangle
glColor3f(1.0f, 0.0f, 1.0f);
// Magenta
glVertex2f(0.1f, -0.6f);
glVertex2f(0.7f, -0.6f);
glVertex2f(0.4f, -0.1f);
glColor3f(1.0f, 1.0f, 0.0f);
// Yellow
glVertex2f(0.3f, -0.4f);
glVertex2f(0.9f, -0.4f);
glVertex2f(0.6f, -0.9f);
glEnd();
glBegin(GL_POLYGON);
// The vertices form one closed
polygon
glColor3f(0.0f, 1.0f, 1.0f);
// Cyan
glVertex2f(0.4f, 0.2f);
glVertex2f(0.6f, 0.2f);
glVertex2f(0.7f, 0.4f);
glVertex2f(0.6f, 0.6f);
glVertex2f(0.4f, 0.6f);
glVertex2f(0.3f, 0.4f);
glEnd();
glFlush();
// Render now
}
// Main function:
GLUT runs as a Console Application
int
main(int argc,
char** argv)
{
glutInit(&argc, argv);
// Initialize GLUT
glutInitWindowSize(320, 320);
// Set the initial Window's width
and height
glutInitWindowPosition(50, 50);
// Position the initial Window's top-left corner
glutCreateWindow("2D Shapes");
// Create window with the given
title
glutDisplayFunc(display);
// Register callback handler for
window re-paint event
glutMainLoop();
// Enter infinitely
event-processing loop
return 0; } |
|