Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions PPMLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef PPMLoader_D
#define PPMLoader_D
#include "includes.h"


class PPMLoader {
public:

// Constructor
PPMLoader();
GLubyte* loadPPM(char* file, int* width, int* height, int* max);
};

#endif
3 changes: 2 additions & 1 deletion includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
#include "PMath/PVector.h"

#include "Material.h"
#include "Light.h"
#include "Light.h"
#include "PPMLoader.h"
60 changes: 49 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const float mouseSensitivity = 0.01;

/* Light Items */
Light *light1;
Light *light2;

/* Material Definitions*/
Material *m1;
Expand All @@ -31,6 +32,13 @@ Material *m1;
#include "SceneGraph/sceneGraph.h"
SceneGraph *SG;

/* Texture */

GLubyte* snailTex;
int width, height, maks;
GLuint textures[1];


/* Node ID's */
int masterID = 0;
int getID() {
Expand Down Expand Up @@ -62,9 +70,9 @@ void initGraph() {
//MODEL
//we will now add a teapot model to the graph as a child of the
//transformation node
// NodeModel *M1 = new NodeModel(Teapot, m1);
NodeModel *M1 = new NodeModel(Teapot, m1);
//insert the node into the graph
// SG->insertChildNodeHere(M1);
SG->insertChildNodeHere(M1);


//THE SAME FLOW CAN BE USED TO DYNAMICALLY ADD NODES
Expand All @@ -83,13 +91,20 @@ void drawGround()
{
for (int z = 0; z < size * 2; z++)
{
glTexCoord2f(0, 0);
glNormal3f(0, 1, 0);
glVertex3f(x - size / 2, 1.0f, -z + size / 2);

glNormal3f(0, 1, 0);
glTexCoord2f(0, 1);
glVertex3f(x + 1 - size / 2, 1.0f, -z + size / 2);

glNormal3f(0, 1, 0);
glTexCoord2f(1, 1);
glVertex3f(x + 1 - size / 2, 1.0f, -z - 1 + size / 2);

glNormal3f(0, 1, 0);
glTexCoord2f(1, 0);
glVertex3f(x - size / 2, 1.0f, -z - 1 + size / 2);
}
}
Expand Down Expand Up @@ -150,7 +165,7 @@ void display()
glPushMatrix();

light1->enable();

light2->enable();
SG->draw();
glPopMatrix();

Expand Down Expand Up @@ -248,6 +263,10 @@ void init()
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_TEXTURE_2D);
//generate 2 texture IDs, store them in array "textures"
glGenTextures(1, textures);

glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Expand All @@ -265,20 +284,39 @@ void init()
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

// Define our lights
Param pos = {0.0f, 1.0f, 80.0f, 1.0f};
Param pos = {20.0f, 20.0f, 20.0f, 1.0f};
Param spec = {1.0f, 1.0f, 1.0f, 1.0f};
Param dif = {0.0f, 0.0f, 0.0f, 1.0f};
Param dif = {1.0f, 1.0f, 1.0f, 1.0f};
Param amb = {1.0f, 1.0f, 1.0f, 1.0f};
light1 = new Light(1, pos, dif, spec, amb);

Param ambM = {0.05f, 0.0f, 0.0f, 1.0f};
Param difM = {0.5f, 0.4f, 0.4f, 1.0f};
Param specM = {0.7f, 0.04f, 0.04f, 1.0f};
float reflect = 0.78125f;
// Define our lights
Param pos1 = { -20.0f, 20.0f, -20.0f, 1.0f};
Param spec1 = {1.0f, 1.0f, 1.0f, 1.0f};
Param dif1 = {1.0f, 1.0f, 1.0f, 1.0f};
Param amb1 = {1.0f, 1.0f, 1.0f, 1.0f};
light2 = new Light(2, pos1, dif1, spec1, amb1);

Param ambM = {1.0f, 1.0f, 1.0f, 1.0f};
Param difM = {1.0f, 1.0f, 1.0f, 1.0f};
Param specM = {1.0f, 1.0f, 1.0f, 1.0f};
float reflect = 78.125f;
m1 = new Material(difM, specM, ambM, reflect);

light1->enable();
light2->enable();

m1->enable();
PPMLoader *ppm = new PPMLoader();
// LOAD TEXTURE
snailTex = ppm->loadPPM("textures/wood.ppm", &width, &height, &maks);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, snailTex);



SG = new SceneGraph();
initGraph();
Expand All @@ -289,7 +327,7 @@ void printStartMenu()
{
// printf("\033[H\033[J");
printf("***********************************\n");
printf("**** TITLE ***\n");
printf("**** Nagger ***\n");
printf("***********************************\n");
printf("\n");

Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PROGRAM_NAME= starFoxClone
run: $(PROGRAM_NAME)
./$(PROGRAM_NAME)$(EXEEXT)

$(PROGRAM_NAME): main.o $(MATH_LIB)/PVector.o $(MATH_LIB)/PPoint.o $(SG_LIB)/node.o $(SG_LIB)/nodeGroup.o $(SG_LIB)/nodeModel.o $(SG_LIB)/nodeTransform.o $(SG_LIB)/sceneGraph.o Light.o Material.o
$(PROGRAM_NAME): main.o $(MATH_LIB)/PVector.o $(MATH_LIB)/PPoint.o $(SG_LIB)/node.o $(SG_LIB)/nodeGroup.o $(SG_LIB)/nodeModel.o $(SG_LIB)/nodeTransform.o $(SG_LIB)/sceneGraph.o Light.o Material.o PPMLoader.o
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)

clean:
Expand Down
9 changes: 5 additions & 4 deletions ppmloader.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include "includes.h"

PPMLoader::PPMLoader(){

GLubyte *image;
}


GLubyte* ppmloader::LoadPPM(char* file, int* width, int* height, int* max)
GLubyte* PPMLoader::loadPPM(char* file, int* width, int* height, int* max)
{
GLubyte* img;
FILE *fd;
Expand Down Expand Up @@ -44,7 +45,7 @@ GLubyte* ppmloader::LoadPPM(char* file, int* width, int* height, int* max)

/* calculate number of pixels and allocate storage for this */
nm = n*m;
img = malloc(3*sizeof(GLuint)*nm);
img = (GLubyte *)malloc(3*sizeof(GLuint)*nm);
s=255.0/k;

/* for every pixel, grab the read green and blue values, storing them in the image data array */
Expand Down
Loading