Skip to content

Commit

Permalink
Textures!
Browse files Browse the repository at this point in the history
  • Loading branch information
confuzedskull committed Dec 13, 2014
1 parent b7ae8ac commit 0ef117d
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ pip-log.txt

# Mac crap
.DS_Store
._.DS_Store
._confuzedskull.bmp
._settings.ini

# CodeBlocks stuff
2DWorld.cbp
Expand Down
3 changes: 2 additions & 1 deletion data/objects/object#10.rso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
680.000 456.000
90.100
90.000
64 64
1 0 0
0 1 0
0 0 0
1
0
0
1
0
2.000
Expand Down
3 changes: 2 additions & 1 deletion data/objects/object#11.rso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
584.000 360.000
90.100
90.000
64 64
0 0 1
0 1 0
0 0 0
1
0
0
1
0
2.000
Expand Down
5 changes: 3 additions & 2 deletions data/objects/object#3.pso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
632.000 408.000
90.100
90.000
32 32
0.5 0.5 0.5
0 1 0
0 0 0
1
0
0
1
0
1.000
Expand Down Expand Up @@ -36,7 +37,7 @@
-1
0
632.000 408.000
90.100
90.000
0.015
0.000
0.000
Expand Down
5 changes: 3 additions & 2 deletions data/objects/object#4.pso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
728.000 408.000
90.100
90.000
32 32
0.5 0.5 0.5
0 1 0
0 0 0
1
0
0
1
0
1.000
Expand Down Expand Up @@ -36,7 +37,7 @@
-1
0
728.000 408.000
90.100
90.000
0.015
0.000
0.000
Expand Down
5 changes: 3 additions & 2 deletions data/objects/object#5.pso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
728.000 312.000
90.100
90.000
32 32
0.5 0.5 0.5
0 1 0
0 0 0
1
0
0
1
0
1.000
Expand Down Expand Up @@ -36,7 +37,7 @@
-1
0
728.000 312.000
90.100
90.000
0.015
0.000
0.000
Expand Down
5 changes: 3 additions & 2 deletions data/objects/object#6.pso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
632.000 312.000
90.100
90.000
32 32
0.5 0.5 0.5
0 1 0
0 0 0
1
0
0
1
0
1.000
Expand Down Expand Up @@ -36,7 +37,7 @@
-1
0
632.000 312.000
90.100
90.000
0.015
0.000
0.000
Expand Down
3 changes: 2 additions & 1 deletion data/objects/object#7.dro
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
680.000 360.000
90.100
0.000
64 64
0 0 0
0 1 0
0 0 0
1
0
1
1
0
1.000
0.000
Expand Down
3 changes: 2 additions & 1 deletion data/objects/object#8.rso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
776.000 360.000
90.100
90.000
64 64
1 1 0
0 1 0
0 0 0
1
0
0
1
0
2.000
Expand Down
3 changes: 2 additions & 1 deletion data/objects/object#9.rso
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
680.000 264.000
90.100
90.000
64 64
0 1 0
0 1 0
0 0 0
1
0
0
1
0
2.000
Expand Down
2 changes: 1 addition & 1 deletion data/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ show_rts_objects = 1
default_height = 32
default_width = 32
default_x = 1224
default_y = 431
default_y = 432
[rts_object]
default_height = 64
default_width = 64
Expand Down
Binary file added graphics/confuzedskull.bmp
Binary file not shown.
4 changes: 3 additions & 1 deletion include/basic_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ class basic_object
float get_radius();
float get_rotation();
bool filled;//whether the body of the object is visible
bool bordered;//whether or not a border should be shown
bool bordered;//whether or not the object has a border
bool textured;//whether the object has a texture
bool visible;//whether the object should be shown or not
bool selected;//whether the object has been selected or not
bool enabled;//whether the object should be updated or not
void show();//make the object visible
void hide();//make the object invisible
void render_border();//draw the border
void render_texture();
void set_position(int x, int y);
void set_dimensions(int w, int h);
basic_object();
Expand Down
38 changes: 38 additions & 0 deletions include/graphics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* This file is a part of 2DWorld - The Generic 2D Game Engine
Copyright (C) 2014 James Nakano
2DWorld is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2DWorld is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the rest of 2DWorld. If not, see <http://www.gnu.org/licenses/>.*/

#ifndef GRAPHICS_H
#define GRAPHICS_H
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#ifdef _WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif

namespace graphics
{
extern GLuint texture;
void load();
};

#endif // GRAPHICS_H
2 changes: 2 additions & 0 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int32_t audio::to_int32(char* buffer, int length)

void audio::load()
{
std::clog<<"loading audio..\n";
char file_info[4];
int16_t format_type, channels, byte_sample, bit_sample;
int32_t chunk_size, sample_rate, byte_rate, data_size;
Expand Down Expand Up @@ -145,6 +146,7 @@ void audio::load()
alSourcefv(source, AL_POSITION, source_position);
alSourcefv(source, AL_VELOCITY, source_velocity);
alSourcei(source, AL_LOOPING, AL_FALSE);
std::clog<<"audio loaded.\n";
}

void audio::play()
Expand Down
53 changes: 35 additions & 18 deletions src/basic_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "basic_object.h"
#include "window.h"
#include "distance.h"
#include "graphics.h"
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
Expand All @@ -33,7 +34,7 @@
#include <sstream>
#include <math.h>

//initialize static variable
//initialize static variables
int basic_object::total_objects=0;
point2i basic_object::default_position = point2i(0,0);

Expand Down Expand Up @@ -143,29 +144,20 @@ void basic_object::render_shape()
{
if(filled)
{
glPushMatrix();//need push and pop so that entire scene isn't rotated
glTranslatef(position.x,position.y,0.0);//translate object according to coordinates
glRotatef(rotation,0,0,1);//rotates object with object.rotation
glTranslatef(-position.x,-position.y,0.0);//translate object according to coordinates
glColor3f(fill_color.r,fill_color.g,fill_color.b);//color the square with object.fill_color
glBegin(GL_POLYGON);//draws a filled in rectangle
glVertex2f(xmin, ymin); // The bottom left corner
glVertex2f(xmin, ymax); // The top left corner
glVertex2f(xmax, ymax); // The top right corner
glVertex2f(xmax, ymin); // The bottom right corner
glEnd();//finish drawing
glPopMatrix();//reset transformation matrix
}
}

void basic_object::render_border()
{
if(bordered)
{
glPushMatrix();//need push and pop so that entire scene isn't rotated
glTranslatef(position.x,position.y,0.0);//translate object according to coordinates
glRotatef(rotation,0,0,1);//rotates object with object.rotation
glTranslatef(-position.x,-position.y,0.0);//translate object according to coordinates
glColor3f(border_color.r,border_color.g,border_color.b);
glBegin(GL_LINES);//draws lines (in this case, a rectangle)
glVertex2f(xmin, ymax);//top left corner
Expand All @@ -177,17 +169,38 @@ void basic_object::render_border()
glVertex2f(xmin, ymin);//bottom left corner
glVertex2f(xmin, ymax);//top left corner
glEnd();
glPopMatrix();//reset transformation matrix
}
}

void basic_object::render_texture()
{
if(textured)
{
glBindTexture(GL_TEXTURE_2D, graphics::texture);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2f(xmin, ymin);
glTexCoord2i(0, 1); glVertex2f(xmin, ymax);
glTexCoord2i(1, 1); glVertex2f(xmax, ymax);
glTexCoord2i(1, 0); glVertex2f(xmax, ymin);
glEnd();
glDisable(GL_TEXTURE_2D);
}
}

void basic_object::render()//draws the object
{
if(visible)
{
glPushMatrix();//need push and pop so that entire scene isn't rotated
glTranslatef(position.x,position.y,0.0);//translate object according to coordinates
glRotatef(rotation,0,0,1);//rotates object with object.rotation
glTranslatef(-position.x,-position.y,0.0);//translate object according to coordinates
render_shape();
render_border();
render_texture();
mark_selected();
glPopMatrix();//reset transformation matrix
}
}

Expand All @@ -203,14 +216,15 @@ basic_object::basic_object()
set_dimensions(64,64);
marker_width=5;
marker_height=5;
marker_color=BLACK;
border_color=BLACK;
fill_color.randomize();
fill_color.changed=false;
filled=true;
marker_color=BLACK;
border_color=BLACK;
bordered=false;
show();
textured=false;
selected=false;
show();
}

basic_object::basic_object(int x, int y, int w, int h)
Expand All @@ -222,30 +236,33 @@ basic_object::basic_object(int x, int y, int w, int h)
marker_width=5;
marker_height=5;
marker_color=BLACK;
border_color=BLACK;
fill_color.randomize();
fill_color.changed=false;
filled=true;
border_color=BLACK;
bordered=false;
show();
textured=false;
selected=false;
show();
}

basic_object::basic_object(int x, int y, int w, int h, color c)
{
number=++total_objects;
position.set(x,y);
rotation=0.0f;
set_dimensions(w,h);
marker_width=5;
marker_height=5;
marker_color=BLACK;
border_color=BLACK;
fill_color.set(c);
fill_color.changed=false;
filled=true;
border_color=BLACK;
bordered=false;
show();
textured=false;
selected=false;
show();
}

basic_object::~basic_object(){}
Loading

0 comments on commit 0ef117d

Please sign in to comment.