Commit a593ba08 authored by Håkon Berg Borhaug's avatar Håkon Berg Borhaug
Browse files

Completed first 8 labs

parent e59cae5b
......@@ -35,6 +35,8 @@ set( INCLUDE
include/SceneObject.hpp
include/Character.hpp
include/Utils.hpp
include/Snow.hpp
include/Text.hpp
include/stb_image.h
)
......@@ -44,6 +46,8 @@ set( SRCS
src/GameManager.cpp
src/SceneObject.cpp
src/Character.cpp
src/Snow.cpp
src/Text.cpp
src/stb_image.cpp
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.15.2, 2022-03-18T15:47:19. -->
<!-- Written by QtCreator 4.15.2, 2022-04-06T23:19:49. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -8,6 +8,8 @@
#include "Landscape.hpp"
#include "Character.hpp"
#include "Camera.hpp"
#include "Snow.hpp"
#include "Text.hpp"
class GameManager : public SceneObject
{
......@@ -27,5 +29,7 @@ class GameManager : public SceneObject
std::shared_ptr<Landscape> ls_;
std::shared_ptr<Character> character_;
std::shared_ptr<Camera> cam_;
std::shared_ptr<Snow> snow_;
std::shared_ptr<Text> text_;
};
#pragma once
#include <windows.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "SceneObject.hpp"
#include "../../glm-master/glm/glm.hpp"
#define MAX_PARTICLES 2000
typedef struct // Create A Structure For Particle
{
bool active; // Active (Yes/No)
float life; // Particle Life
float fade; // Fade Speed
float r; // Red Value
float g; // Green Value
float b; // Blue Value
float x; // X Position
float y; // Y Position
float z; // Z Position
float xi; // X Direction
float yi; // Y Direction
float zi; // Z Direction
float xg; // X Gravity
float yg; // Y Gravity
float zg; // Z Gravity
}
particle; // Particle Structure
class Snow : public SceneObject
{
public:
Snow();
~Snow();
protected:
void privateInit();
void privateRender();
void privateUpdate();
void setUpTexture();
private:
unsigned int texture;
particle particles[MAX_PARTICLES];
float slowdown = 2.0f;
float zoom = -40.0f;
GLuint loop;
};
#pragma once
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <string>
#include "SceneObject.hpp"
class Text : public SceneObject
{
public:
Text();
~Text();
protected:
void privateInit();
void privateRender();
void privateUpdate();
private:
std::string string_;
};
......@@ -340,7 +340,7 @@ void Character::setUpHBTextures()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
int width, height, nrChannels;
unsigned char *data = stbi_load("C:/dev/DTE-3609/start_code/resources/test.jpg", &width, &height, &nrChannels, 0);
unsigned char *data = stbi_load("C:/dev/DTE-3609/start_code/resources/HP.jpg", &width, &height, &nrChannels, 0);
if (data)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
......
......@@ -22,6 +22,12 @@ void GameManager::privateInit()
character_.reset(new Character());
this->addSubObject(character_);
snow_.reset(new Snow());
this->addSubObject(snow_);
text_.reset(new Text());
this->addSubObject(text_);
}
void GameManager::privateRender()
......@@ -45,3 +51,5 @@ std::shared_ptr<Character> GameManager::getCharacter()
{
return character_;
}
......@@ -37,6 +37,7 @@ void Landscape::privateInit()
void Landscape::privateRender()
{
// Draw filled polygons
glColor3f(0.0f, 1.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
......@@ -60,15 +61,43 @@ void Landscape::privateRender()
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 12, 4);
glDisableClientState(GL_VERTEX_ARRAY);
// Drawing wireframe of polygons
glEnable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(-1.0, -1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 4, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 8, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 12, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_POLYGON_OFFSET_LINE);
}
void Landscape::privateUpdate()
{
//glMatrixMode(GL_MODELVIEW);
//glPushMatrix();
//glLoadIdentity();
//glTranslatef(10.0f, 0.0f, 0.0f);
//glRotatef(1.0f, 0.0f, 1.0f, 0.0f);
//glPopMatrix();
}
#include "../include/Snow.hpp"
#include "../../glm-master/glm/glm.hpp"
#include "../../glm-master/glm/gtc/matrix_transform.hpp"
#include "../include/Utils.hpp"
#include "../include/stb_image.h"
#include <iostream>
#include <fstream>
#include <random>
Snow::Snow() {
}
Snow::~Snow() {
}
void Snow::privateInit() {
for (loop = 0; loop < MAX_PARTICLES; loop++) {
particles[loop].active=true; // Make All The Particles Active
particles[loop].life=100.0f; // Give All The Particles Full Life
particles[loop].fade=float(rand()%100)/1000.0f+0.003f; // Random Fade Speed
particles[loop].xi=float((rand()%1000)-500.0f)*10.0f; // Random Speed On X Axis
particles[loop].yi=float((rand()%50)-25.0f)*10.0f; // Random Speed On Y Axis
particles[loop].zi=float((rand()%50)-25.0f)*10.0f; // Random Speed On Z Axis
particles[loop].xg=0.0f; // Set Horizontal Pull To Zero
particles[loop].yg=-2.8f; // Set Vertical Pull Downward
particles[loop].zg=0.0f; // Set Pull On Z Axis To Zero
}
setUpTexture();
}
void Snow::privateRender() {
/*
glLoadIdentity(); // Reset The ModelView Matrix
for (loop=0;loop<MAX_PARTICLES;loop++) // Loop Through All The Particles
{
if (particles[loop].active) // If The Particle Is Active
{
float x=particles[loop].x; // Grab Our Particle X Position
float y=particles[loop].y; // Grab Our Particle Y Position
float z=particles[loop].z+zoom; // Particle Z Pos + Zoom
glColor3f(1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_TRIANGLE_STRIP); // Build Quad From A Triangle Strip
glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); // Top Right
glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z); // Top Left
glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z); // Bottom Right
glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z); // Bottom Left
glEnd(); // Done Building Triangle Strip
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
particles[loop].x+=particles[loop].xi/(slowdown*1000);// Move On The X Axis By X Speed
particles[loop].y+=particles[loop].yi/(slowdown*1000);// Move On The Y Axis By Y Speed
particles[loop].z+=particles[loop].zi/(slowdown*1000);// Move On The Z Axis By Z Speed
particles[loop].xi+=particles[loop].xg; // Take Pull On X Axis Into Account
particles[loop].yi+=particles[loop].yg; // Take Pull On Y Axis Into Account
particles[loop].zi+=particles[loop].zg; // Take Pull On Z Axis Into Account
particles[loop].life-=particles[loop].fade; // Reduce Particles Life By 'Fade'
if (particles[loop].life<0.0f) // If Particle Is Burned Out
{
particles[loop].life=100.0f; // Give It New Life
particles[loop].fade=float(rand()%100)/1000.0f+0.003f; // Random Fade Value
particles[loop].x=0.0f; // Center On X Axis
particles[loop].y=40.0f; // Center On Y Axis
particles[loop].z=0.0f; // Center On Z Axis
particles[loop].xi=float((rand()%1000)-500.0f); // X Axis Speed And Direction
particles[loop].yi=float(-30.0f); // Y Axis Speed And Direction
particles[loop].zi=float((rand()%60)-30.0f); // Z Axis Speed And Direction
}
}
}
*/
}
void Snow::privateUpdate() {
}
void Snow::setUpTexture() {
// textureArray_.push_back(glm::vec2(0.0f, 1.0f));
// textureArray_.push_back(glm::vec2(1.0f, 1.0f));
// textureArray_.push_back(glm::vec2(1.0f, 0.0f));
// textureArray_.push_back(glm::vec2(0.0f, 0.0f));
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
int width, height, nrChannels;
unsigned char *data = stbi_load("C:/dev/DTE-3609/start_code/resources/snowflake.jpg", &width, &height, &nrChannels, 0);
if (data)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
}
else
{
std::cout << "FAILED TO LOAD TEXTURE: " << stbi_failure_reason() << std::endl;
}
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free(data);
}
#include "../include/Text.hpp"
Text::Text() {
}
Text::~Text() {
}
void Text::privateInit() {
string_ = "This is a test";
}
void Text::privateRender() {
glEnable(GL_COLOR_MATERIAL);
glColor3f(1.0f, 1.0f, 1.0f);
glRasterPos3f(-100.0f, 200.0f, 0.0f);
glLineWidth(100.0f);
for (char& c : string_) {
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, c);
}
glLineWidth(1.0f);
glDisable(GL_COLOR_MATERIAL);
}
void Text::privateUpdate() {
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment