0% found this document useful (0 votes)
50 views

Data Representation in OpenGL

This document outlines data representation in OpenGL and provides examples of rendering a cube and teapot. It also discusses non-photorealistic rendering shader examples and the results of compiling a stereo rendering program.

Uploaded by

fathoni.am
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Data Representation in OpenGL

This document outlines data representation in OpenGL and provides examples of rendering a cube and teapot. It also discusses non-photorealistic rendering shader examples and the results of compiling a stereo rendering program.

Uploaded by

fathoni.am
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Outline

• Data Representation in OpenGL


• Shader Example: NPR
• StereoRendering Compilation Result
Data Representation in OpenGL
A Cube
// v6----- v5
// /| /|
// v1------v0|
// | | | |
// | |v7---|-|v4
// |/ |/
// v2------v3
Describing coordinates
GLfloat vertices[] = {1,1,1, -1,1,1, -1,-1,1, 1,-1,1, // v0-v1-v2-v3
1,1,1, 1,-1,1, 1,-1,-1, 1,1,-1, // v0-v3-v4-v5
1,1,1, 1,1,-1, -1,1,-1, -1,1,1, // v0-v5-v6-v1
-1,1,1, -1,1,-1, -1,-1,-1, -1,-1,1, // v1-v6-v7-v2
-1,-1,-1, 1,-1,-1, 1,-1,1, -1,-1,1, // v7-v4-v3-v2
1,-1,-1, -1,-1,-1, -1,1,-1, 1,1,-1}; // v4-v7-v6-v5
Describing normals
GLfloat normals[] = {0,0,1, 0,0,1, 0,0,1, 0,0,1, // v0-v1-v2-v3
1,0,0, 1,0,0, 1,0,0, 1,0,0, // v0-v3-v4-v5
0,1,0, 0,1,0, 0,1,0, 0,1,0, // v0-v5-v6-v1
-1,0,0, -1,0,0, -1,0,0, -1,0,0, // v1-v6-v7-v2
0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0, // v7-v4-v3-v2
0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1}; // v4-v7-v6-v5
Describing colors
GLfloat colors[] = {1,1,1, 1,1,0, 1,0,0, 1,0,1, // v0-v1-v2-v3
1,1,1, 1,0,1, 0,0,1, 0,1,1, // v0-v3-v4-v5
1,1,1, 0,1,1, 0,1,0, 1,1,0, // v0-v5-v6-v1
1,1,0, 0,1,0, 0,0,0, 1,0,0, // v1-v6-v7-v2
0,0,0, 0,0,1, 1,0,1, 1,0,0, // v7-v4-v3-v2
0,0,1, 0,0,0, 0,1,0, 0,1,1}; // v4-v7-v6-v5
Describing indices
GLubyte indices[] = {0,1,2,3,
4,5,6,7,
8,9,10,11,
12,13,14,15,
16,17,18,19,
20,21,22,23};
Drawing
void draw3()
{
// enable and specify pointers to vertex arrays
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glColorPointer(3, GL_FLOAT, 0, colors);
glVertexPointer(3, GL_FLOAT, 0, vertices);

glPushMatrix();
glTranslatef(-2, -2, 0); // move to bottom-left

glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, indices);

glPopMatrix();

glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays


glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
Teapot vertices?
GLfloat teapotVertices[] = {
-3.00000f, 1.80000f, 0.000000f, -2.99160f, 1.80000f, -0.0810000f, -2.99160f, 1.80000f, 0.0810000f, // line 16
-2.98945f, 1.66616f, 0.000000f, -2.98500f, 1.92195f, 0.000000f,
-2.98117f, 1.66784f, -0.0810000f, -2.98117f, 1.66784f, 0.0810000f,
-2.97669f, 1.92024f, -0.0810000f, -2.97669f, 1.92024f, 0.0810000f,
-2.96880f, 1.80000f, -0.144000f, -2.96880f, 1.80000f, 0.144000f,
-2.95871f, 1.67241f, -0.144000f, -2.95871f, 1.67241f, 0.144000f,
…………………………………………………………………………………………………..
…………………………………………………………………………………………………
-2.95760f, 1.53480f, 0.000000f, -2.95412f, 1.91561f, -0.144000f,
3.41645f, 2.47237f, -0.0579960f, 3.41645f, 2.47237f, 0.0579960f,
3.41645f, 2.47237f, 0.0579960f, 3.42488f, 2.46261f, 0.000000f,
3.42812f, 2.47734f, 0.000000f, 3.43400f, 2.47290f, 0.000000f,
3.43400f, 2.47290f, 0.000000f //line 1649
};

Complex Objects?
Shader Example: NPR
Shader Example: NPR
StereoRendering Compilation Result
StereoRendering (Window 1)
StereoRendering (Window 2)
Plan
• Analyze StereoRendering Program

You might also like