Hello, im working on a project for my calculus teacher and I am required to make a 3D device to help display my example for the lesson that we are learning.
I already knew Allegro so I decided to use AllegroGL for the 3D portion and everything works fine. My problem is that when I try to run the same program on a school computer it crashes. The reason I know that it crashes on set_gfx_mode is because I placed allegro_message boxes before and after set_gfx_mode and it wont display the one after. I was wondering since Allegro needs files like alleg44.dll to run on a different computer, i may have to get another file for the AllegroGL part of it. Since its a school computer, administrator is blocked so I wont be able to install programs. One more thing, since I cant install programs, I am using Dev C++ Portable on my USB Flash Drive and I have installed Allegro and AllegroGL from the devpack
Here is my code
#include <allegro.h>
#include <alleggl.h>
#include <vector>
#include <string>
using namespace std;
// Font
FONT* Font;
// Possible primitives
const int NumPrimitives = 10;
const int Primitives[NumPrimitives] =
{
GL_POINTS,
GL_LINES,
GL_LINE_STRIP,
GL_LINE_LOOP,
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN,
GL_QUADS,
GL_QUAD_STRIP,
GL_POLYGON
};
// Names
string PrimitiveNames[NumPrimitives] =
{
"GL_POINTS",
"GL_LINES",
"GL_LINE_STRIP",
"GL_LINE_LOOP",
"GL_TRIANGLES",
"GL_TRIANGLE_STRIP",
"GL_TRIANGLE_FAN",
"GL_QUADS",
"GL_QUAD_STRIP",
"GL_POLYGON"
};
// A struct to hold a point.
struct Point
{
float x, y;
Point(float x, float y) : x(x), y(y) {}
};
void Init()
{
// Start up Allegro and AllegroGL systems
allegro_init();
install_allegro_gl();
install_keyboard();
install_mouse();
allegro_message("Passed Initial Startup");
allegro_gl_clear_settings();
// Set some AllegroGL options
allegro_gl_set(AGL_DOUBLEBUFFER, true);
allegro_gl_set(AGL_COLOR_DEPTH, 16);
allegro_gl_set(AGL_RENDERMETHOD, true);
allegro_gl_set(AGL_SUGGEST, AGL_DOUBLEBUFFER | AGL_COLOR_DEPTH | AGL_RENDERMETHOD);
allegro_message("Passed Initial Graphics");
// Set up a suitable viewing window
set_color_depth(32);
allegro_message("Passed Initial Color Depth");
set_gfx_mode(GFX_OPENGL_WINDOWED, 800, 600, 0, 0); //GFX_OPENGL_WINDOWED
allegro_message("Passed Initial Window");
// Fill front-facing polygons and line back-facing ones.
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_LINE);
// Set the background color to black (R,G,B,A)
glClearColor(0, 0, 0, 0);
}
int main()
{
Init();
std::vector<Point> vertices;
bool mouse_b1 = false;
bool upd_title = true;
char* title_buf = 0;
float mx = 0.0, my = 0.0;
int prim = 0;
while(!key[KEY_ESC])
{
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT);
//Draw Graph Lines
// Poll the mouse
poll_mouse();
mx = (mouse_x / 320.0) - 1.0;
my = (-mouse_y / 240.0) + 1.0;
// Check to see if a vertex needs to be added
if(!(mouse_b & 1) && mouse_b1) // Mouse button 1 up
{
vertices.push_back(Point(mx, my));
}
mouse_b1 = mouse_b & 1;
// Check to see if the primitive should be drawn
if((mouse_b & 2) && (vertices.size() > 0))
{
glBegin(Primitives[prim]);
glColor3f(0.0, 0.0, 1.0);
for(unsigned int i = 0; i < vertices.size(); i++)
{
glVertex2f(vertices[i].x, vertices[i].y);
}
glEnd();
glBegin(GL_LINES);
glVertex2f(0.0f, 300.0f);
glVertex2f(800.0f, 300.0f);
glEnd( );
glFlush();
allegro_gl_flip();
set_window_title("Press any key to continue.");
upd_title = true;
clear_keybuf();
readkey();
}
// Clear the vertex list if necessary
if(key[KEY_DEL] && (vertices.size() > 0))
{
vertices.clear();
}
// Draw the vertices and the mouse cursor
glPointSize(5.0);
glBegin(GL_POINTS);
glColor3f(1.0, 0.0, 0.0);
for(unsigned int i = 0; i < vertices.size(); i++)
{
glVertex2f(vertices[i].x, vertices[i].y);
}
glColor3f(0.8, 0.8, 0.8);
glVertex2f(mx, my);
glEnd();
// Cycle through the available primitives.
if(key[KEY_1]) { prim = 0; upd_title = true; }
if(key[KEY_2]) { prim = 1; upd_title = true; }
if(key[KEY_3]) { prim = 2; upd_title = true; }
if(key[KEY_4]) { prim = 3; upd_title = true; }
if(key[KEY_5]) { prim = 4; upd_title = true; }
if(key[KEY_6]) { prim = 5; upd_title = true; }
if(key[KEY_7]) { prim = 6; upd_title = true; }
if(key[KEY_8]) { prim = 7; upd_title = true; }
if(key[KEY_9]) { prim = 8; upd_title = true; }
if(key[KEY_0]) { prim = 9; upd_title = true; }
// Set the window title
if(upd_title)
{
std::string title = string("Type: ") +
PrimitiveNames[prim] +
string(" | LMB: Add vtx | RMB: Draw prim. | 0-9: Change prim. type | DEL: Clear");
delete[] title_buf;
title_buf = new char[title.size()];
strcpy(title_buf, title.c_str());
set_window_title(title_buf);
upd_title = false;
}
// Flush & flip.
glFlush();
allegro_gl_flip();
}
return 0;
}
END_OF_MAIN();