Skip to content

Commit 3862647

Browse files
authored
Merge pull request #7 from rickgaiser/nehe
Add NeHe lesson 2/3/4/5 examples
2 parents 4fa4c6d + 302c4be commit 3862647

File tree

8 files changed

+559
-0
lines changed

8 files changed

+559
-0
lines changed

examples/nehe/lesson02/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
EE_BIN = lesson02.elf
2+
EE_CFLAGS := -I$(PS2SDK)/ports/include $(EE_CFLAGS)
3+
EE_CXXFLAGS := -I$(PS2SDK)/ports/include $(EE_CXXFLAGS)
4+
EE_OBJS = lesson2.o
5+
EE_LDFLAGS += -L$(PS2SDK)/ports/lib
6+
EE_LIBS = -lps2glut -lps2gl -lps2stuff -lpad -ldma
7+
8+
ifeq ($(DEBUG), 1)
9+
EE_CFLAGS += -D_DEBUG -g -O0
10+
EE_CXXFLAGS += -D_DEBUG -g -O0
11+
endif
12+
13+
# Disabling warnings
14+
WARNING_FLAGS = -Wno-strict-aliasing -Wno-conversion-null
15+
16+
# VU0 code is broken so disable for now
17+
EE_CFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS
18+
EE_CXXFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS
19+
20+
all: $(EE_BIN)
21+
$(EE_STRIP) --strip-all $(EE_BIN)
22+
23+
testpc:
24+
g++ lesson2.cpp -lglut -lGL -o lesson02
25+
./lesson02
26+
27+
clean:
28+
rm -f $(EE_BIN) $(EE_OBJS)
29+
30+
run: $(EE_BIN)
31+
ps2client -h 192.168.1.10 execee host:$(EE_BIN)
32+
33+
reset:
34+
ps2client -h 192.168.1.10 reset
35+
36+
sim: $(EE_BIN)
37+
PCSX2 --elf=$(PWD)/$(EE_BIN)
38+
39+
include $(PS2SDK)/samples/Makefile.pref
40+
include $(PS2SDK)/samples/Makefile.eeglobal_cpp

examples/nehe/lesson02/lesson2.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <GL/gl.h> // The GL Header File
2+
#include <GL/glut.h> // The GL Utility Toolkit (Glut) Header
3+
#include <math.h>
4+
5+
//-----------------------------------------------------------------------------
6+
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
7+
{
8+
GLdouble xmin, xmax, ymin, ymax;
9+
10+
ymax = zNear * tan(fovy * M_PI / 360.0f);
11+
ymin = -ymax;
12+
xmin = ymin * aspect;
13+
xmax = ymax * aspect;
14+
15+
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
16+
}
17+
18+
void init(GLvoid) // Create Some Everyday Functions
19+
{
20+
21+
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
22+
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
23+
glClearDepth(1.0f); // Depth Buffer Setup
24+
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
25+
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
26+
//glEnable(GL_COLOR_MATERIAL);
27+
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
28+
}
29+
30+
void display(void) // Create The Display Function
31+
{
32+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
33+
glLoadIdentity(); // Reset The Current Modelview Matrix
34+
glTranslatef(-1.5f, 0.0f, -6.0f); // Move Left 1.5 Units And Into The Screen 6.0
35+
glBegin(GL_TRIANGLES); // Drawing Using Triangles
36+
glVertex3f(0.0f, 1.0f, 0.0f); // Top
37+
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
38+
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
39+
glEnd(); // Finished Drawing The Triangle
40+
glTranslatef(3.0f, 0.0f, 0.0f); // Move Right 3 Units
41+
glBegin(GL_QUADS); // Draw A Quad
42+
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
43+
glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
44+
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
45+
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
46+
glEnd();
47+
48+
49+
glutSwapBuffers();
50+
// Swap The Buffers To Not Be Left With A Clear Screen
51+
}
52+
53+
void reshape(int w, int h) // Create The Reshape Function (the viewport)
54+
{
55+
glViewport(0, 0, w, h);
56+
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
57+
glLoadIdentity(); // Reset The Projection Matrix
58+
if (h == 0) // Calculate The Aspect Ratio Of The Window
59+
gluPerspective(80, (float)w, 1.0, 5000.0);
60+
else
61+
gluPerspective(80, (float)w / (float)h, 1.0, 5000.0);
62+
glMatrixMode(GL_MODELVIEW); // Select The Model View Matrix
63+
glLoadIdentity(); // Reset The Model View Matrix
64+
}
65+
66+
int main(int argc, char **argv) // Create Main Function For Bringing It All Together
67+
{
68+
glutInit(&argc, argv); // Erm Just Write It =)
69+
init();
70+
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // Display Mode
71+
glutInitWindowSize(640, 448); // If glutFullScreen wasn't called this is the window size
72+
glutCreateWindow("NeHe's OpenGL Framework"); // Window Title (argv[0] for current directory as title)
73+
glutDisplayFunc(display); // Matching Earlier Functions To Their Counterparts
74+
glutReshapeFunc(reshape);
75+
glutMainLoop(); // Initialize The Main Loop
76+
77+
return 0;
78+
}

examples/nehe/lesson03/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
EE_BIN = lesson03.elf
2+
EE_CFLAGS := -I$(PS2SDK)/ports/include $(EE_CFLAGS)
3+
EE_CXXFLAGS := -I$(PS2SDK)/ports/include $(EE_CXXFLAGS)
4+
EE_OBJS = lesson3.o
5+
EE_LDFLAGS += -L$(PS2SDK)/ports/lib
6+
EE_LIBS = -lps2glut -lps2gl -lps2stuff -lpad -ldma
7+
8+
ifeq ($(DEBUG), 1)
9+
EE_CFLAGS += -D_DEBUG -g -O0
10+
EE_CXXFLAGS += -D_DEBUG -g -O0
11+
endif
12+
13+
# Disabling warnings
14+
WARNING_FLAGS = -Wno-strict-aliasing -Wno-conversion-null
15+
16+
# VU0 code is broken so disable for now
17+
EE_CFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS
18+
EE_CXXFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS
19+
20+
all: $(EE_BIN)
21+
$(EE_STRIP) --strip-all $(EE_BIN)
22+
23+
testpc:
24+
g++ lesson3.cpp -lglut -lGL -o lesson03
25+
./lesson03
26+
27+
clean:
28+
rm -f $(EE_BIN) $(EE_OBJS)
29+
30+
run: $(EE_BIN)
31+
ps2client -h 192.168.1.10 execee host:$(EE_BIN)
32+
33+
reset:
34+
ps2client -h 192.168.1.10 reset
35+
36+
sim: $(EE_BIN)
37+
PCSX2 --elf=$(PWD)/$(EE_BIN)
38+
39+
include $(PS2SDK)/samples/Makefile.pref
40+
include $(PS2SDK)/samples/Makefile.eeglobal_cpp

examples/nehe/lesson03/lesson3.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <GL/gl.h> // The GL Header File
2+
#include <GL/glut.h> // The GL Utility Toolkit (Glut) Header
3+
#include <math.h>
4+
5+
//-----------------------------------------------------------------------------
6+
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
7+
{
8+
GLdouble xmin, xmax, ymin, ymax;
9+
10+
ymax = zNear * tan(fovy * M_PI / 360.0f);
11+
ymin = -ymax;
12+
xmin = ymin * aspect;
13+
xmax = ymax * aspect;
14+
15+
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
16+
}
17+
18+
void init(GLvoid) // Create Some Everyday Functions
19+
{
20+
21+
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
22+
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
23+
glClearDepth(1.0f); // Depth Buffer Setup
24+
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
25+
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
26+
//glEnable(GL_COLOR_MATERIAL);
27+
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
28+
}
29+
30+
void display(void) // Create The Display Function
31+
{
32+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
33+
glLoadIdentity(); // Reset The Current Modelview Matrix
34+
glTranslatef(-1.5f, 0.0f, -6.0f); // Move Left 1.5 Units And Into The Screen 6.0
35+
glBegin(GL_TRIANGLES); // Drawing Using Triangles
36+
glColor3f(1.0f, 0.0f, 0.0f); // Set The Color To Red
37+
glVertex3f(0.0f, 1.0f, 0.0f); // Top
38+
glColor3f(0.0f, 1.0f, 0.0f); // Set The Color To Green
39+
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
40+
glColor3f(0.0f, 0.0f, 1.0f); // Set The Color To Blue
41+
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
42+
glEnd(); // Finished Drawing The Triangle
43+
glTranslatef(3.0f, 0.0f, 0.0f); // Move Right 3 Units
44+
glColor3f(0.5f, 0.5f, 1.0f); // Set The Color To Blue One Time Only
45+
glBegin(GL_QUADS); // Draw A Quad
46+
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
47+
glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
48+
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
49+
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
50+
glEnd(); // Done Drawing The Quad
51+
52+
53+
glutSwapBuffers();
54+
// Swap The Buffers To Not Be Left With A Clear Screen
55+
}
56+
57+
void reshape(int w, int h) // Create The Reshape Function (the viewport)
58+
{
59+
glViewport(0, 0, w, h);
60+
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
61+
glLoadIdentity(); // Reset The Projection Matrix
62+
if (h == 0) // Calculate The Aspect Ratio Of The Window
63+
gluPerspective(80, (float)w, 1.0, 5000.0);
64+
else
65+
gluPerspective(80, (float)w / (float)h, 1.0, 5000.0);
66+
glMatrixMode(GL_MODELVIEW); // Select The Model View Matrix
67+
glLoadIdentity(); // Reset The Model View Matrix
68+
}
69+
70+
int main(int argc, char **argv) // Create Main Function For Bringing It All Together
71+
{
72+
glutInit(&argc, argv); // Erm Just Write It =)
73+
init();
74+
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // Display Mode
75+
glutInitWindowSize(640, 448); // If glutFullScreen wasn't called this is the window size
76+
glutCreateWindow("NeHe's OpenGL Framework"); // Window Title (argv[0] for current directory as title)
77+
glutDisplayFunc(display); // Matching Earlier Functions To Their Counterparts
78+
glutReshapeFunc(reshape);
79+
glutMainLoop(); // Initialize The Main Loop
80+
81+
return 0;
82+
}

examples/nehe/lesson04/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
EE_BIN = lesson04.elf
2+
EE_CFLAGS := -I$(PS2SDK)/ports/include $(EE_CFLAGS)
3+
EE_CXXFLAGS := -I$(PS2SDK)/ports/include $(EE_CXXFLAGS)
4+
EE_OBJS = lesson4.o
5+
EE_LDFLAGS += -L$(PS2SDK)/ports/lib
6+
EE_LIBS = -lps2glut -lps2gl -lps2stuff -lpad -ldma
7+
8+
ifeq ($(DEBUG), 1)
9+
EE_CFLAGS += -D_DEBUG -g -O0
10+
EE_CXXFLAGS += -D_DEBUG -g -O0
11+
endif
12+
13+
# Disabling warnings
14+
WARNING_FLAGS = -Wno-strict-aliasing -Wno-conversion-null
15+
16+
# VU0 code is broken so disable for now
17+
EE_CFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS
18+
EE_CXXFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS
19+
20+
all: $(EE_BIN)
21+
$(EE_STRIP) --strip-all $(EE_BIN)
22+
23+
testpc:
24+
g++ lesson4.cpp -lglut -lGL -o lesson04
25+
./lesson04
26+
27+
clean:
28+
rm -f $(EE_BIN) $(EE_OBJS)
29+
30+
run: $(EE_BIN)
31+
ps2client -h 192.168.1.10 execee host:$(EE_BIN)
32+
33+
reset:
34+
ps2client -h 192.168.1.10 reset
35+
36+
sim: $(EE_BIN)
37+
PCSX2 --elf=$(PWD)/$(EE_BIN)
38+
39+
include $(PS2SDK)/samples/Makefile.pref
40+
include $(PS2SDK)/samples/Makefile.eeglobal_cpp

examples/nehe/lesson04/lesson4.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <GL/gl.h> // The GL Header File
2+
#include <GL/glut.h> // The GL Utility Toolkit (Glut) Header
3+
#include <math.h>
4+
5+
float rtri; // Angle For The Triangle
6+
float rquad; // Angle For The Quad
7+
8+
//-----------------------------------------------------------------------------
9+
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
10+
{
11+
GLdouble xmin, xmax, ymin, ymax;
12+
13+
ymax = zNear * tan(fovy * M_PI / 360.0f);
14+
ymin = -ymax;
15+
xmin = ymin * aspect;
16+
xmax = ymax * aspect;
17+
18+
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
19+
}
20+
21+
void init(GLvoid) // Create Some Everyday Functions
22+
{
23+
24+
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
25+
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
26+
glClearDepth(1.0f); // Depth Buffer Setup
27+
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
28+
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
29+
//glEnable(GL_COLOR_MATERIAL);
30+
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
31+
}
32+
33+
void display(void) // Create The Display Function
34+
{
35+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
36+
glLoadIdentity(); // Reset The Current Modelview Matrix
37+
glPushMatrix();
38+
glTranslatef(-1.5f, 0.0f, -6.0f); // Move Left 1.5 Units And Into The Screen 6.0
39+
glRotatef(rtri, 0.0f, 1.0f, 0.0f); // Rotate The Triangle On The Y axis
40+
glBegin(GL_TRIANGLES); // Drawing Using Triangles
41+
glColor3f(1.0f, 0.0f, 0.0f); // Set The Color To Red
42+
glVertex3f(0.0f, 1.0f, 0.0f); // Top
43+
glColor3f(0.0f, 1.0f, 0.0f); // Set The Color To Green
44+
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
45+
glColor3f(0.0f, 0.0f, 1.0f); // Set The Color To Blue
46+
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
47+
glEnd(); // Finished Drawing The Triangle
48+
49+
glLoadIdentity(); // Reset The Current Modelview Matrix
50+
glTranslatef(1.5f, 0.0f, -6.0f); // Move Right 1.5 Units And Into The Screen 6.0
51+
glRotatef(rquad, 1.0f, 0.0f, 0.0f); // Rotate The Quad On The X axis
52+
glColor3f(0.5f, 0.5f, 1.0f); // Set The Color To Blue One Time Only
53+
glBegin(GL_QUADS); // Draw A Quad
54+
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
55+
glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
56+
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
57+
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
58+
glEnd(); // Done Drawing The Quad
59+
glPopMatrix();
60+
rtri += 0.2f; // Increase The Rotation Variable For The Triangle ( NEW )
61+
rquad -= 0.15f; // Decrease The Rotation Variable For The Quad ( NEW )
62+
63+
64+
glutSwapBuffers();
65+
// Swap The Buffers To Not Be Left With A Clear Screen
66+
}
67+
68+
void reshape(int w, int h) // Create The Reshape Function (the viewport)
69+
{
70+
glViewport(0, 0, w, h);
71+
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
72+
glLoadIdentity(); // Reset The Projection Matrix
73+
if (h == 0) // Calculate The Aspect Ratio Of The Window
74+
gluPerspective(80, (float)w, 1.0, 5000.0);
75+
else
76+
gluPerspective(80, (float)w / (float)h, 1.0, 5000.0);
77+
glMatrixMode(GL_MODELVIEW); // Select The Model View Matrix
78+
glLoadIdentity(); // Reset The Model View Matrix
79+
}
80+
81+
int main(int argc, char **argv) // Create Main Function For Bringing It All Together
82+
{
83+
glutInit(&argc, argv); // Erm Just Write It =)
84+
init();
85+
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // Display Mode
86+
glutInitWindowSize(640, 448); // If glutFullScreen wasn't called this is the window size
87+
glutCreateWindow("NeHe's OpenGL Framework"); // Window Title (argv[0] for current directory as title)
88+
glutDisplayFunc(display); // Matching Earlier Functions To Their Counterparts
89+
glutReshapeFunc(reshape);
90+
glutIdleFunc(display);
91+
glutMainLoop(); // Initialize The Main Loop
92+
93+
return 0;
94+
}

0 commit comments

Comments
 (0)