1. (In C#) How do I create a menu in which I can choose between different options?

^like that
You might look at the RadioCheck property
http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
Informative x 1 (list)

2. Ugh... Been trying to get this for awhile now. This should be easy, but for some reason I guess I just suck with vectors.

I need to check to see if a cord(x, y) is within the diamond in the square.

in this function

Code:
        private bool IsoLogic(Rectangle dimension, Vector2 sp)
{
Vector2 start = new Vector2(dimension.X, dimension.Y);

if (sp.X > start.X && sp.Y > start.Y)
{
if ((sp.Y >= sp.X / 2) && (sp.X < start.X + 32 && sp.Y < start.Y + 16)) //check upper left
{
return true;
}
if ((sp.X <= sp.Y / 2) && (sp.X < start.X + 64 && sp.Y < start.Y + 16)) //check upper right
{
return true;
}
if ((sp.X <= sp.Y) && (sp.X < start.X + 32 && sp.Y < start.Y + 32))  //check bottom left
{
return true;
}
if ((sp.X >= sp.Y) && (sp.X < start.X + 64 && sp.Y < start.Y + 32)) //check bottom right
{
return true;
}
}
return false;
}
This is the closest I've gotten, but it still doesn't work correctly.
Vector2 start gets the upper left corner of the square.

Vector2 sp is the vector of the mouse which I am checking to see if it is inside of the diamond or not.

3. Time to ask for help at Facepunch too I guess. I'm trying to add physics to my 3D game engine however the mesh is ending up horribly mis-aligned.

I'm using Jitter since it seems quite nice and it doesn't want to do everything for you. I'm trying to build a compound shape of convex hulls, one for each mesh in the model. Currently however the different hulls are being transformed incorrectly, resulting in a misaligned mesh.

http://pastebin.com/PNkWVfsz is my current physics entity class. Any help is much appreciated.
How do you define the origin of your models? IIRC Jitter adjusts the origin of rigid bodies to their center of mass.
Informative x 1 (list)

4. Ugh... Been trying to get this for awhile now. This should be easy, but for some reason I guess I just suck with vectors.

I need to check to see if a cord(x, y) is within the diamond in the square.

in this function

Code:
        private bool IsoLogic(Rectangle dimension, Vector2 sp)
{
Vector2 start = new Vector2(dimension.X, dimension.Y);

if (sp.X > start.X && sp.Y > start.Y)
{
if ((sp.Y >= sp.X / 2) && (sp.X < start.X + 32 && sp.Y < start.Y + 16)) //check upper left
{
return true;
}
if ((sp.X <= sp.Y / 2) && (sp.X < start.X + 64 && sp.Y < start.Y + 16)) //check upper right
{
return true;
}
if ((sp.X <= sp.Y) && (sp.X < start.X + 32 && sp.Y < start.Y + 32))  //check bottom left
{
return true;
}
if ((sp.X >= sp.Y) && (sp.X < start.X + 64 && sp.Y < start.Y + 32)) //check bottom right
{
return true;
}
}
return false;
}
This is the closest I've gotten, but it still doesn't work correctly.
Vector2 start gets the upper left corner of the square.

Vector2 sp is the vector of the mouse which I am checking to see if it is inside of the diamond or not.
ratio = 64.0 / 32.0; // ratio of x/y
maxdist = 32.0;

dx = (center.x - pos.x);
dy = (center.y - pos.y) * ratio;

d = abs(dx) + abs(dy);

return (d <= maxdist);

The metric to get "circles" that look like diamonds is $\sum _{k=1} ^n |a_k - b_k|$, and it defines taxicab geometry. Yours is just a squished diamond, so one axis gets scaled before summation.

Edited:

Don't worry if that doesn't make any sense

5. I want to make a board game using Java. (to learn it better)
I am a beginner and i was wondering what imports to use and if anyone could point me in the right direction with where to start.
Also tutorials that i should definitely read for this.

I have an image with the board itself.
Things what i want to be able to do:
- i want to be able to specify the amount of players and then have that amount of pawns.
- a dice
- drag and drop the pawns

6. @Silverboarder

The real Drag & Drop interface works easy with components, but as you just
wish to DND with some own images within the scope of your own program
(and just within one JComponent) you can skip DND interface this and just
use the mouse listener for this.

For the easy way (just mouse listener) you just need minimal knowledge of swing.
You only want an initial frame asking how many players (possible board+pawn images)
and reuse this frame to add the a panel as canvas for the drawing.

More interesting is the Graphis2D interface, you will use it for drawing your images.
But in most simple case you will only use the drawImage.
Just make a subclass of JPanel and overwrite the paint. From here you can use the
Graphics2D interface. Add the mouse listener (to either frame or panel) and you're
almost done ;)

It becomes more complicated if you actually want to add game-logic etc.

Marco

7. Can anyone see anything in my shader class that would cause a segfault?


#pragma once

#include <string>
#include <map>
#include <vector>
#include <GL/glew.h>

{
protected:
std::map< std::string, GLuint > UniformVariableIDList;
std::map< std::string, GLuint > AttributeVariableIDList;
public:

///
/// \brief Empty constructor
///

///
/// \brief Construct shader with given files
///
Shader(const std::string &vertFileName, const std::string &fragFileName);

///
/// \brief Deconstructor
///

///
/// \brief Retreive the shaders ID
///

///
/// \brief Bind the shader for use
///
void Bind();

///
///
static void Unbind();

///
/// \brief Get the ID of a given attribute
/// \param Attribute name
///
GLuint GetAttribute(const std::string attName);

///
/// \brief Get the ID of a given uniform
/// \param Uniform name
///
GLuint GetUniform(const std::string uniName);
};




#include <iostream>
#include <fstream>
#include <GL/glew.h>
#include <glm/glm.hpp>

{
AttributeVariableIDList.clear();
UniformVariableIDList.clear();

{
std::string Line = "";
}

{
std::string Line = "";
}

GLint Result = GL_FALSE;
int InfoLogLength;

printf("Compiling shader : %s ", vertFileName.c_str());
char const * VertexSourcePointer = VertexShaderCode.c_str();

printf("Compiling shader : %s ", fragFileName.c_str());
char const * FragmentSourcePointer = FragmentShaderCode.c_str();

GLuint ProgramID = glCreateProgram();

/// Check the program
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> ProgramErrorMessage( glm::max(InfoLogLength, int(1)) );
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);

}

{
}

{
try
{
{
std::string Line = "";
}
}
catch(int e)
{
std::cout << "Failed to open Vertex shader, using basic shader." << std::endl << e << std::endl;
}
}

{
try
{
{
std::string Line = "";
}
}
catch(int e)
{
std::cout << "Failed to open Frag shader, using basic shader." << std::endl << e << std::endl;
FragmentShaderCode = "void main(){  gl_FragColor = vec4(1,1,1,1); }";
}
}

{
std::cout << "Compiling Vertex Shader" << std::endl;
char const * VertexSourcePointer = VertexShaderCode.c_str();

}

{
std::cout << "Compiling Fragment Shader" << std::endl;
char const * FragmentSourcePointer = FragmentShaderCode.c_str();

}

{
}

{
}

{
glUseProgram(0);
}

{
std::map<std::string, GLuint>::iterator it = AttributeVariableIDList.find(attName);
if (it != AttributeVariableIDList.end())
{
return it->second;
}

AttributeVariableIDList[attName] = attribute;
}

{
std::map<std::string, GLuint>::iterator it = UniformVariableIDList.find(uniName);
if (it != UniformVariableIDList.end())
{
return it->second;
}

UniformVariableIDList[uniName] = uniform;

}

Dumb x 1 (list)

8. ratio = 64.0 / 32.0; // ratio of x/y
maxdist = 32.0;

dx = (center.x - pos.x);
dy = (center.y - pos.y) * ratio;

d = abs(dx) + abs(dy);

return (d <= maxdist);

The metric to get "circles" that look like diamonds is $\sum _{k=1} ^n |a_k - b_k|$, and it defines taxicab geometry. Yours is just a squished diamond, so one axis gets scaled before summation.

Edited:

Don't worry if that doesn't make any sense

Heh well its alright I got it now... Took me way too long to make this algorithm...

Code:
            float min;
float high;

if (sp.X > start.X && sp.Y > start.Y && (sp.X < start.X + 64 && sp.Y < start.Y + 32))
{
if (nc.X < 32)
{
min = 16 - (nc.X / 2);
high = (nc.X / 2) + 16;

if (nc.Y > min  && nc.Y < high)
return true;
}
else if (nc.X >= 32)
{
min = (nc.X / 2) - 16;
high = 32 - min;

if (nc.Y > min && nc.Y < high)
return true;
}
}
return false;
Math is my weakness... and it really shows in my programming :/

9. Can anyone see anything in my shader class that would cause a segfault?

[code]
use a debugger

set a breakpoint

and find out yourself

seriously that should be in the OP - "set a breakpoint and step through your code"
Agree x 2 (list)

10. use a debugger

set a breakpoint

and find out yourself

seriously that should be in the OP - "set a breakpoint and step through your code"
This is what my debbuger gives me:
Code:
valgrind ./FPSd
==2350== Memcheck, a memory error detector
==2350== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==2350== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==2350== Command: ./FPSd
==2350==
==2350==    at 0x0: ???
==2350==    by 0x804D4CF: Block::Block() (Block.cpp:4)
==2350==    by 0x804A39E: Block3d::Block3d() (Chunk.hpp:6)
==2350==    by 0x804A3FC: Chunk::Chunk() (Chunk.hpp:18)
==2350==    by 0x804A14A: Program::Program() (Program.cpp:7)
==2350==    by 0x804D310: main (Main.cpp:6)
==2350==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==2350==
==2350==
==2350== Process terminating with default action of signal 11 (SIGSEGV)
==2350==    at 0x0: ???
==2350==    by 0x804D4CF: Block::Block() (Block.cpp:4)
==2350==    by 0x804A39E: Block3d::Block3d() (Chunk.hpp:6)
==2350==    by 0x804A3FC: Chunk::Chunk() (Chunk.hpp:18)
==2350==    by 0x804A14A: Program::Program() (Program.cpp:7)
==2350==    by 0x804D310: main (Main.cpp:6)
==2350==
==2350== HEAP SUMMARY:
==2350==     in use at exit: 9,785,834 bytes in 338 blocks
==2350==   total heap usage: 583 allocs, 245 frees, 9,862,264 bytes allocated
==2350==
==2350== LEAK SUMMARY:
==2350==    definitely lost: 0 bytes in 0 blocks
==2350==    indirectly lost: 0 bytes in 0 blocks
==2350==      possibly lost: 4,118 bytes in 112 blocks
==2350==    still reachable: 9,781,716 bytes in 226 blocks
==2350==         suppressed: 0 bytes in 0 blocks
==2350== Rerun with --leak-check=full to see details of leaked memory
==2350==
==2350== For counts of detected and suppressed errors, rerun with: -v
==2350== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 88 from 11)
Segmentation fault

11. then put a breakpoint on the constructor and step through it until you find the offending line
Agree x 1 (list)

12. In C#, is it possible to copy entire folders, to another folder, filled with different files that can be images, text, more folders, and files that have unknown file extensions.

13. In C#, is it possible to copy entire folders, to another folder, filled with different files that can be images, text, more folders, and files that have unknown file extensions.
yes
Dumb x 4 Informative x 1 (list)

14. How do you define the origin of your models? IIRC Jitter adjusts the origin of rigid bodies to their center of mass.
Fixed it from help of noone (the guy who made the library), but yes, you're right.

15. wow you're a lot of help!!

Funley, I found this to at least copy files

static void Main(string[] args)
{
DirectoryInfo sourceDir = new DirectoryInfo("c:\\a");
DirectoryInfo destinationDir = new DirectoryInfo("c:\\b");

CopyDirectory(sourceDir, destinationDir);

}

static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
{
if (!destination.Exists)
{
destination.Create();
}

// Copy all files.
FileInfo[] files = source.GetFiles();
foreach (FileInfo file in files)
{
file.CopyTo(Path.Combine(destination.FullName,
file.Name));
}

// Process subdirectories.
DirectoryInfo[] dirs = source.GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
// Get destination directory.
string destinationDir = Path.Combine(destination.FullName, dir.Name);

// Call CopyDirectory() recursively.
CopyDirectory(dir, new DirectoryInfo(destinationDir));
}
}

That at least copies the directory, should get you started
Friendly x 1 (list)

16. wow you're a lot of help!!

Funley, I found this to at least copy files

static void Main(string[] args)
{
DirectoryInfo sourceDir = new DirectoryInfo("c:\\a");
DirectoryInfo destinationDir = new DirectoryInfo("c:\\b");

CopyDirectory(sourceDir, destinationDir);

}

static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
{
if (!destination.Exists)
{
destination.Create();
}

// Copy all files.
FileInfo[] files = source.GetFiles();
foreach (FileInfo file in files)
{
file.CopyTo(Path.Combine(destination.FullName,
file.Name));
}

// Process subdirectories.
DirectoryInfo[] dirs = source.GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
// Get destination directory.
string destinationDir = Path.Combine(destination.FullName, dir.Name);

// Call CopyDirectory() recursively.
CopyDirectory(dir, new DirectoryInfo(destinationDir));
}
}

That at least copies the directory, should get you started
Honestly, I thought I was in a different thread

17. snip im stupid
Agree x 1 Friendly x 1 Disagree x 1 (list)

18. I'm trying to go through a few sfml tutorials.

Here are the errors I'm getting:
sfmlHello.cpp: In function ‘int main()’:
sfmlHello.cpp:7:16: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
sfmlHello.cpp:9:17: error: ‘class sf::RenderWindow’ has no member named ‘pollEvent’

Here is the code:
Code:
#include <SFML/Graphics.hpp>

int main(){
sf::VideoMode VMode(800, 600, 32);
sf::RenderWindow Window(VMode, "SFMLCoder Tutorial - Empty Window");

while (Window.isOpen()){
sf::Event Event;
while (Window.pollEvent(Event)){
switch(Event.Type) {
case sf::Event::Closed:
Window.Close();
break;
default:
break;
}
}
Window.Clear(sf::Color(0, 255, 255));
Window.Display();
}
return 0;
}

19. I'm trying to go through a few sfml tutorials.

Here are the errors I'm getting:
sfmlHello.cpp: In function ‘int main()’:
sfmlHello.cpp:7:16: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
Are you sure you're using the right version of SFML? SFML 2.0 has "isOpen" and "pollEvent", but SFML 1.6 has "isOpened" and no pollEvent.

EDIT: Also, you need to include <SFML/Window.hpp>

20. Are you sure you're using the right version of SFML? SFML 2.0 has "isOpen" and "pollEvent", but SFML 1.6 has "isOpened" and no pollEvent.

EDIT: Also, you need to include <SFML/Window.hpp>
Tried isOpened and it also didn't recognize that as a member.
I'm on Ubuntu, and I used the official repositories: sudo apt-get install libsfml-dev.

21. Tried isOpened and it also didn't recognize that as a member.
I'm on Ubuntu, and I used the official repositories: sudo apt-get install libsfml-dev.
Older SFML versions don't use camel-back notation. It should be IsOpened, not isOpened.

22. I just remembered why i never learned unrealscript, because OO used to hurt my head.
I have decided to try and pick it up, Anyone got any tips?

23. I'm on Ubuntu, and I used the official repositories: sudo apt-get install libsfml-dev.
The ubuntu packages are the stable version (1.6). You need to compile the 2.0 version yourself. Not hard, the cmake-gui package can help you if you're unfamiliar with cmake

24. -Figure It out-

25. I'm trying to minimize the communication between my server and client for example having the server tell the client that a character shoots in one direction, and the client will know what weapon that character is using, what kind of projectile to spawn, and where other players are for the projectile to collide with. Is this is a bad way of doing it because it can potentially be unreliable, or is better because it will reduce lag?

26. I'm trying to minimize the communication between my server and client for example having the server tell the client that a character shoots in one direction, and the client will know what weapon that character is using, what kind of projectile to spawn, and where other players are for the projectile to collide with. Is this is a bad way of doing it because it can potentially be unreliable, or is better because it will reduce lag?
As long as you verify everything on your server, it should be fine.

For example, for a multiplayer game I am (slowly) working on in my spare time, I intend to have the AI be predicted on the client. Whenever an AI updates his movements or behaviors, it will send an update to the relevant clients - in the case of movement, it will simply use vectors, or directions with speed.

So instead of constantly updating an AI's position while traveling in a straight line, I simply send to the client that an AI is going in a straight line with a certain speed, and let the client predict it.

Cuts down on networking, but minimalizes chances of cheating and such because things are still verified by the server. While this means there may be client issues (such as slightly teleporting AI), I personally think it's the best approach.

So you can do your idea there, but just be sure you keep track of everything so you can verify it on the server. While you should never trust your clients to make decisions, there's no reason to hold their hand through everything - just be sure you can verify any important decisions like shooting or movement.
Informative x 1 (list)

27. I just remembered why i never learned unrealscript, because OO used to hurt my head.
I have decided to try and pick it up, Anyone got any tips?
Mess around with UTGame and see how it works before trying to inherit from the UDK or non-UDK bases. There's a few tutorials around (see UDKGems) but you're best off learning from the documentation at UDN and code that ships with the UDK (UnCodeX is a brilliant program).

Don't edit anything in any of the Development/Src/ folders that already exist however, always derive.

28. thanks for the help guys
Friendly x 2 (list)

29. Anyon know the formula for accessing element in a 1D array that has been created for 3D?

Like with a 2d one its:
blah ar[X*Y];
ar[X + Y*Width];

30. Anyon know the formula for accessing element in a 1D array that has been created for 3D?

Like with a 2d one its:
blah ar[X*Y];
ar[X + Y*Width];

31. Anyon know the formula for accessing element in a 1D array that has been created for 3D?

Like with a 2d one its:
blah ar[X*Y];
ar[X + Y*Width];
It's the x value...
plus the y value time the width of a row...
plus z value times the number of elements in an xy slice (width * height).
The width factors out, so you get this:

Code:
array[x + (y + z * height) * width]
You'll notice that this bit
Code:
y + z * height
looks a lot like what you had for 2D:
Code:
X + Y*Width
...which is because it is a lot like that.
Winner x 2 Programming King x 1 (list)

32. Im trying to read a text file to start with text drawing in OGL, for it I use this method:
bool SOGLF::BitmapText::LoadFile(const std::string& imageFile, const std::string& fontFile, int heightSize, int widthSize )
{
std::ifstream myfile;

try
{
myfile.open(fontFile.c_str());
if (myfile.is_open())
{
int arrVal = 0;
while ( myfile.good() )
{
std::string line;
std::getline (myfile,line);

int numS = 0;
int lineSp = 0;
int posVal = 0;

while(lineSp < line.size())
{
if(line.at(lineSp) == ' ')
{
Positions[arrVal][posVal] = atoi(line.substr(numS, lineSp - numS).c_str());
numS = lineSp + 1;
posVal++;
}

lineSp++;
}

arrVal++;
}
myfile.close();
}
}
catch(int e)
{
myfile.close();
result = false;
}

for(int i = 0; i < 256; i++)
{
std::cout << Positions[i][0] << ":" << Positions[i][1] << ":" << Positions[i][2] << ":"<< Positions[i][3] << std::endl;
}

return result;
}

And the file I am reading is this:
Code:
0 0 0 0
10 0 10 16
20 0 10 16
30 0 10 16
40 0 10 16
50 0 10 16
60 0 10 16
70 0 10 16
80 0 10 16
90 0 0 0
100 0 0 0
110 0 10 16
120 0 10 16
130 0 0 0
140 0 10 16
150 0 10 16
0 16 10 16
10 16 10 16
20 16 10 16
30 16 10 16
40 16 10 16
50 16 10 16
60 16 10 16
70 16 10 16
80 16 10 16
90 16 10 16
100 16 10 16
110 16 10 16
120 16 10 16
130 16 10 16
140 16 10 16
150 16 10 16
0 32 10 16
10 32 3 16
20 32 6 16
30 32 10 16
40 32 10 16
50 32 10 16
60 32 10 16
70 32 3 16
80 32 5 16
90 32 5 16
100 32 10 16
110 32 10 16
120 32 3 16
130 32 6 16
140 32 3 16
150 32 10 16
0 48 10 16
10 48 5 16
20 48 10 16
30 48 10 16
40 48 10 16
50 48 10 16
60 48 10 16
70 48 10 16
80 48 10 16
90 48 10 16
100 48 3 16
110 48 3 16
120 48 6 16
130 48 10 16
140 48 6 16
150 48 10 16
0 64 10 16
10 64 10 16
20 64 10 16
30 64 10 16
40 64 10 16
50 64 10 16
60 64 10 16
70 64 10 16
80 64 10 16
90 64 10 16
100 64 10 16
110 64 10 16
120 64 10 16
130 64 10 16
140 64 10 16
150 64 10 16
0 80 10 16
10 80 10 16
20 80 10 16
30 80 10 16
40 80 10 16
50 80 10 16
60 80 10 16
70 80 10 16
80 80 10 16
90 80 10 16
100 80 10 16
110 80 5 16
120 80 10 16
130 80 5 16
140 80 6 16
150 80 10 16
0 96 3 16
10 96 10 16
20 96 10 16
30 96 10 16
40 96 10 16
50 96 10 16
60 96 10 16
70 96 10 16
80 96 10 16
90 96 3 16
100 96 10 16
110 96 10 16
120 96 10 16
130 96 10 16
140 96 10 16
150 96 10 16
0 112 10 16
10 112 10 16
20 112 10 16
30 112 10 16
40 112 10 16
50 112 10 16
60 112 10 16
70 112 10 16
80 112 10 16
90 112 10 16
100 112 10 16
110 112 6 16
120 112 3 16
130 112 6 16
140 112 10 16
150 112 10 16
0 128 10 16
10 128 10 16
20 128 10 16
30 128 10 16
40 128 10 16
50 128 10 16
60 128 10 16
70 128 10 16
80 128 10 16
90 128 10 16
100 128 10 16
110 128 10 16
120 128 10 16
130 128 10 16
140 128 10 16
150 128 10 16
0 144 10 16
10 144 10 16
20 144 10 16
30 144 10 16
40 144 10 16
50 144 10 16
60 144 10 16
70 144 10 16
80 144 10 16
90 144 10 16
100 144 10 16
110 144 10 16
120 144 10 16
130 144 10 16
140 144 10 16
150 144 10 16
0 160 10 16
10 160 3 16
20 160 10 16
30 160 10 16
40 160 10 16
50 160 10 16
60 160 3 16
70 160 10 16
80 160 10 16
90 160 10 16
100 160 5 16
110 160 10 16
120 160 10 16
130 160 10 16
140 160 10 16
150 160 10 16
0 176 6 16
10 176 10 16
20 176 6 16
30 176 6 16
40 176 5 16
50 176 10 16
60 176 10 16
70 176 6 16
80 176 5 16
90 176 5 16
100 176 6 16
110 176 10 16
120 176 10 16
130 176 10 16
140 176 10 16
150 176 10 16
0 192 10 16
10 192 10 16
20 192 10 16
30 192 10 16
40 192 10 16
50 192 10 16
60 192 10 16
70 192 10 16
80 192 10 16
90 192 10 16
100 192 10 16
110 192 10 16
120 192 10 16
130 192 10 16
140 192 10 16
150 192 10 16
0 208 10 16
10 208 10 16
20 208 10 16
30 208 10 16
40 208 10 16
50 208 10 16
60 208 10 16
70 208 6 16
80 208 10 16
90 208 10 16
100 208 10 16
110 208 10 16
120 208 10 16
130 208 10 16
140 208 10 16
150 208 10 16
0 224 10 16
10 224 10 16
20 224 10 16
30 224 10 16
40 224 10 16
50 224 10 16
60 224 10 16
70 224 10 16
80 224 10 16
90 224 10 16
100 224 10 16
110 224 10 16
120 224 5 16
130 224 5 16
140 224 6 16
150 224 6 16
0 240 10 16
10 240 10 16
20 240 10 16
30 240 10 16
40 240 10 16
50 240 10 16
60 240 10 16
70 240 6 16
80 240 10 16
90 240 10 16
100 240 10 16
110 240 10 16
120 240 10 16
130 240 10 16
140 240 10 16
150 240 10 1
But the output from cout is:
Code:
:::

::
:
::
:
::
:
(::
:
2::
:�
<::
:
F::
:
P::
:
Z:::
d:::
n::
:
x::
:
�:::
�::
:
�::
:
::
:

::
:�
::
:
::
:
(::
:
2::
:
<::
:
F::
:
P::
:
Z::
:
d::
:
n::
:
x::
:
�::
:
�::
:
�::
:�
: :
:

: ::
: ::
: :
:
(: :
:
2: :
:
<: :
:
F: ::M
P: ::
Z: ::
d: :
:
n: :
:
x: ::
�: ::
�: ::
�: :
:
:0:
:

:0::
:0:
:
:0:
:
(:0:
:
2:0:
:
<:0:
:
F:0:
:
P:0:
:
Z:0:
:
d:0::
n:0::
x:0::
�:0:
:
�:0::
�:0:
:
:@:
:

:@:
:
:@:
:
:@:
:
(:@:
:�
2:@:
:
<:@:
:
F:@:
:
P:@:
:
Z:@:
:
d:@:
:
n:@:
:
x:@:
:
�:@:
:
�:@:
:
�:@:
:
:P:
:

:P:
:
:P:
:
:P:
:
(:P:
:
2:P:
:
<:P:
:
F:P:
:
P:P:
:
Z:P:
:
d:P:
:
n:P::
x:P:
:
�:P::
�:P::
�:P:
:0
:::

::
:�
::
:
::
:
(::
:�
2::
:
<::
:
F::
:
P::
:
Z:::
d::
:
n::
:
x::
:
�::
:
�::
:
�::
:
:p:
:

:p:
:
:p:
:
:p:
:
(:p:
:
2:p:
:�
<:p:
:
F:p:
:
P:p:
:
Z:p:
:
d:p:
:
n:p::
x:p::q
�:p::
�:p:
:
�:p:
:
:�:
:

:�:
:
:�:
:
:�:
:
(:�:
:
2:�:
:
<:�:
:
F:�:
:
P:�:
:�
Z:�:
:�
d:�:
:
n:�:
:
x:�:
:
�:�:
:
�:�:
:
�:�:
:�
:�:
:�

:�:
:�
:�:
:
:�:
:�
(:�:
:
2:�:
:�
<:�:
:
F:�:
:
P:�:
:
Z:�:
:
d:�:
:
n:�:
:
x:�:
:
�:�:
:
�:�:
:
�:�:
:
:�:
:

:�::
:�:
:
:�:
:
(:�:
:
2:�:
:
<:�::
F:�:
:
P:�:
:�
Z:�:
:
d:�::
n:�:
:
x:�:
:
�:�:
:
�:�:
:
�:�:
:
:�::�

:�:
:
:�::
:�::
(:�::
2:�:
:
<:�:
:
F:�::
P:�::�
Z:�::�
d:�::
n:�:
:
x:�:
:
�:�:
:
�:�:
:
�:�:
:
:�:
:�

:�:
:�
:�:
:
:�:
:�
(:�:
:
2:�:
:�
<:�:
:
F:�:
:
P:�:
:�
Z:�:
:
d:�:
:
n:�:
:
x:�:
:
�:�:
:
�:�:
:
�:�:
:
:�:
:�

:�:
:�
:�:
:�
:�:
:�
(:�:
:
2:�:
:
<:�:
:
F:�::
P:�:
:
Z:�:
:
d:�:
:
n:�:
:
x:�:
:
�:�:
:
�:�:
:
�:�:
:
:�:
:

:�:
:�
:�:
:
:�:
:
(:�:
:
2:�:
:�
<:�:
:
F:�:
:
P:�:
:
Z:�:
:
d:�:
:
n:�:
:
x:�::
�:�::�
�:�::
�:�::
:�:
:

:�:
:�
:�:
:
:�:
:
(:�:
:
2:�:
:�
<:�:
:
F:�::
P:�:
:
Z:�:
:
d:�:
:
n:�:
:
x:�:
:
�:�:
:
�:�:
:
�:�:
:
Optimistic x 1 (list)

33. Try something like this

Edited:

std::stringstream ss(s);
std::string item;
while(std::getline(ss, item, ' ')) {
Positions[arrVal][posVal] = atoi(item);
}

string::getline has a very nice delimiter parameter that does what you want

Edited:

Oh, I forgot, s in the stringstream would be your string

either that or you could just declare the stringstream and do stringstream.str

34. I got it working by changing the file format to:
Code:
0000 0000 0000 0000
0010 0000 0010 0016
0020 0000 0010 0016
0030 0000 0010 0016
0040 0000 0010 0016
0050 0000 0010 0016
0060 0000 0010 0016
0070 0000 0010 0016
0080 0000 0010 0016
0090 0000 0000 0000
0100 0000 0000 0000
0110 0000 0010 0016
0120 0000 0010 0016
0130 0000 0000 0000
0140 0000 0010 0016
0150 0000 0010 0016
0000 0016 0010 0016
0010 0016 0010 0016
0020 0016 0010 0016
0030 0016 0010 0016
...
IE 4 digits per number

and the code I use now is:
bool result = bitmap.LoadFromFile(imageFile.c_str());
std::ifstream myfile;

try
{
myfile.open(fontFile.c_str());
if (myfile.is_open())
{
int arrVal = 0;
while ( myfile.good() )
{
std::string line;
std::getline (myfile,line);

int jump = 0;
for( int n = 0; n < 4; n++)
{
std::string str = "";
int numb = 0;
int pos = n*5;

str += line[pos];
str += line[pos+1];
str += line[pos+2];
str += line[pos+3];

std::istringstream ( str ) >> numb;

Positions[arrVal][0+n] = numb;
}

arrVal++;
}
myfile.close();
}
}
catch(int e)
{
myfile.close();
result = false;
}

for(int i = 0; i < 256; i++)
{
std::cout << Positions[i][0] << ":" << Positions[i][1] << ":" << Positions[i][2] << ":"<< Positions[i][3] << std::endl;
}
std::cout << "Blah" << std::endl;


which outputs correctly but creates a segfault on returning, do i have to flush a buffer or something that I have missed out?

Edited:

the call stack is:

#0 0x284c6c ??() (/usr/lib/i386-linux-gnu/libstdc++.so.6:??)
#1 0x284cfe std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() () (/usr/lib/i386-linux-gnu/libstdc++.so.6:??)
#2 0x804fb1b Program::Initialize(this=0x808c7d8) (/home/richy/codeblocks/FPS/src/Program.cpp:33)
#3 0x8052b3a main() (/home/richy/codeblocks/FPS/src/Main.cpp:7)

35. segfaults with arrays is usually caused by trying to access an index that doesn't exist in the array

don't know your specific cause since your code looks good to me but it's worth looking into

36. Im putting up the class code incase anyone can see anything:
#ifndef BITMAPTEXT_HPP_INCLUDED
#define BITMAPTEXT_HPP_INCLUDED

#include <GL/gl.h>
#include <vector>
#include "soglf/Texture.hpp"

namespace SOGLF
{
///
/// \brief Class for displaying text onscreen Not implemented yet
///
class BitmapText
{
protected:
GLuint vertexbuffer;
GLuint uvbuffer;
std::vector<GLuint> VertexList;
std::vector<GLuint> UVList;
SOGLF::Texture bitmap;
unsigned short Positions[256][4];
public:
///
/// \brief Empty constructor
///
BitmapText();

///
/// \brief Empty deconstructor
///
~BitmapText();

///
/// \brief Construct class from given arguments
/// \param Bitmap image
/// \param Bitmap position array
/// \param Character size used
/// \param Text to display
bool LoadFile(const std::string& imageFile, const std::string& fontFile , int heightSize, int widthSize);

///
/// \brief Set text
///
void SetText(const std::string& text);
};
}

#endif // BITMAPTEXT_HPP_INCLUDED



#include <GL/glew.h>
#include "soglf/BitmapText.hpp"
#include <GL/glfw.h>
#include <iostream>
#include <fstream>
#include "soglf/Utilities.hpp"

SOGLF::BitmapText::BitmapText()
{
glGenBuffers(1, &vertexbuffer);
glGenBuffers(1, &uvbuffer);
}

SOGLF::BitmapText::~BitmapText()
{
glDeleteBuffers(1, &vertexbuffer);
glDeleteBuffers(1, &uvbuffer);
}

bool SOGLF::BitmapText::LoadFile(const std::string& imageFile, const std::string& fontFile, int heightSize, int widthSize )
{
std::ifstream myfile;

try
{
myfile.open(fontFile.c_str());
if (myfile.is_open())
{
int arrVal = 0;
while ( myfile.good() )
{
std::string line;
std::getline (myfile,line);

for( int n = 0; n < 4; n++)
{
std::string str = "";
int numb = 0;
int pos = n*5;

str += line[pos];
str += line[pos+1];
str += line[pos+2];
str += line[pos+3];

std::istringstream ( str ) >> numb;

Positions[arrVal][0+n] = numb;
}

arrVal++;
}
myfile.close();
}

for(int i = 0; i < 256; i++)
{
std::cout << Positions[i][0] << ":" << Positions[i][1] << ":" << Positions[i][2] << ":" << Positions[i][3] << std::endl;
}
}
catch(int e)
{
std::cout << "Failed to load: " << fontFile << std::endl;
result = false;
}

std::cout << "Blah";

return result;
}

void SOGLF::BitmapText::SetText(const std::string& text)
{

}


Edited:

Changed it from an array of short to just a vector of vec4 and works as planned.

37. OK so I think I have everything setup so that it should draw... but it doesnt.
this is my Orthogonal:
SOGLF::Matrices::Orthogonal =
glm::ortho(
0,
winW,
winH,
0,
1,
-1
);

#version 120
uniform mat4 MVP;
attribute vec4 Position;
attribute vec2 UV;
varying vec2 uv;

void main(){
uv = UV;
gl_Position =  MVP * Position;
}

#version 120
varying vec2 uv;
uniform sampler2D Texture;
uniform vec4 Color;
void main(){
vec4 textur = texture2D( Texture, uv ).rgba;
if(textur.rgb == vec3(1.0f,1.0f,1.0f))    textur.a = Color.a;
textur.rgb = Color.rgb;
gl_FragColor = textur;
}

#ifndef BITMAPTEXT_HPP_INCLUDED
#define BITMAPTEXT_HPP_INCLUDED

#include <GL/gl.h>
#include <vector>
#include "soglf/Texture.hpp"
#include "soglf/Drawable.hpp"

namespace SOGLF
{
///
/// \brief Class for displaying text onscreen Not implemented yet
///
class BitmapText : public SOGLF::Drawable
{
protected:
GLuint vertexbuffer;
GLuint uvbuffer;
std::vector<GLfloat> VertexList;
std::vector<GLfloat> UVList;
SOGLF::Texture bitmap;
std::vector<glm::vec4> Positions;
glm::vec2 Pos;
std::string text;
glm::vec4 Color;

glm::mat4 MVP;

GLuint TextureID;
GLuint ColorID;
GLuint MVPID;
GLuint PositionID;
GLuint UVID;

void Rebuild();
public:
///
/// \brief Empty constructor
///
BitmapText();

///
/// \brief Empty deconstructor
///
~BitmapText();

///
/// \brief Construct class from given arguments
/// \param Bitmap image
/// \param Bitmap position array
bool LoadFile(const std::string& imageFile, const std::string& fontFile );

///
/// \brief Set text
///
void SetText(const std::string& eText);

void SetPosition(const glm::vec2 &pos);

virtual void Update();

virtual void Draw();
};
}

#endif // BITMAPTEXT_HPP_INCLUDED

and the cpp
#include <GL/glew.h>
#include "soglf/BitmapText.hpp"
#include <GL/glfw.h>
#include <iostream>
#include <fstream>
#include "soglf/Utilities.hpp"
#include "soglf/Window.hpp"

SOGLF::BitmapText::BitmapText():
{
Pos = glm::vec2(0.0f);
Color = glm::vec4(1.0f);
text = "hi";

glGenBuffers(1, &vertexbuffer);
glGenBuffers(1, &uvbuffer);

}

SOGLF::BitmapText::~BitmapText()
{
glDeleteBuffers(1, &vertexbuffer);
glDeleteBuffers(1, &uvbuffer);
}

bool SOGLF::BitmapText::LoadFile(const std::string& imageFile, const std::string& fontFile )
{
std::ifstream myfile;

try
{
myfile.open(fontFile.c_str());
if (myfile.is_open())
{
while ( myfile.good() )
{
std::string line;
std::getline (myfile,line);

float x,y,z,w;

std::stringstream strx, stry, strz, strw;

strx << line[0]     << line[1]  << line[2]  << line[3];
stry << line[5]     << line[6]  << line[7]  << line[8];
strz << line[10]    << line[11] << line[12] << line[13];
strw << line[15]    << line[16] << line[17] << line[18];

strx  >> x;  stry  >> y;  strz  >> z;  strw  >> w;

Positions.push_back(glm::vec4(x, y, z, w));

}
myfile.close();
}

//for (unsigned int i = 0; i < Positions.size(); i++)
//{
//std::cout << Positions[i].x << ":" << Positions[i].y << ":" << Positions[i].z << ":" << Positions[i].w << std::endl;
//}
}
catch(int e)
{
std::cout << "Failed to load: " << fontFile << std::endl;
result = false;
}

return result;
}

void SOGLF::BitmapText::SetText(const std::string& eText)
{
text = eText;
Rebuild();
}

void SOGLF::BitmapText::SetPosition(const glm::vec2& pos)
{
Pos = pos;
Rebuild();
}

void SOGLF::BitmapText::Update()
{

}

void SOGLF::BitmapText::Draw()
{
glUniformMatrix4fv(MVPID, 1, GL_FALSE, &MVP[0][0]);

glActiveTexture(GL_TEXTURE0);
bitmap.Bind();
glUniform1i(TextureID, 0);

glUniform4fv(ColorID,1 , &Color[0]);

glEnableVertexAttribArray(PositionID);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
PositionID,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
3,                  // size
GL_FLOAT,           // type
GL_FALSE,           // normalized?
0,                  // stride
(void*)0            // array buffer offset
);

glEnableVertexAttribArray(UVID);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glVertexAttribPointer(
UVID,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
2,                  // size
GL_FLOAT,           // type
GL_FALSE,           // normalized?
0,                  // stride
(void*)0            // array buffer offset
);

glDrawArrays(GL_TRIANGLES, 0, VertexList.size()/3);

glDisableVertexAttribArray(PositionID);
glDisableVertexAttribArray(UVID);

SOGLF::Texture::Unbind();
}

void SOGLF::BitmapText::Rebuild()
{
VertexList.clear();
UVList.clear();

glm::vec2 winS = SOGLF::WindowClass::Window.GetSize();
float disp = 0.0f;
for(int i = 0; i < text.size(); i++)
{
glm::vec4 charRect = Positions[text.c_str()[i]];

VertexList.push_back(0.0f + disp);
VertexList.push_back(charRect.w/winS.y);
VertexList.push_back(0.0f);

VertexList.push_back(0.0f + disp);
VertexList.push_back(0.0f);
VertexList.push_back(0.0f);

VertexList.push_back(charRect.z/winS.x + disp);
VertexList.push_back(charRect.w/winS.y);
VertexList.push_back(0.0f);

VertexList.push_back(charRect.z/winS.x + disp);
VertexList.push_back(charRect.w/winS.y);
VertexList.push_back(0.0f);

VertexList.push_back(0.0f + disp);
VertexList.push_back(0.0f);
VertexList.push_back(0.0f);

VertexList.push_back(charRect.z/winS.x + disp);
VertexList.push_back(0.0f);
VertexList.push_back(0.0f);

UVList.push_back(charRect.x / bitmap.GetSize().x);
UVList.push_back(charRect.y / bitmap.GetSize().y);

UVList.push_back(charRect.x / bitmap.GetSize().x);
UVList.push_back((charRect.y + charRect.w) / bitmap.GetSize().y);

UVList.push_back((charRect.x + charRect.z ) / bitmap.GetSize().x);
UVList.push_back(charRect.y / bitmap.GetSize().y);

UVList.push_back((charRect.x + charRect.z ) / bitmap.GetSize().x);
UVList.push_back(charRect.y / bitmap.GetSize().y);

UVList.push_back(charRect.x / bitmap.GetSize().x);
UVList.push_back((charRect.y + charRect.w) / bitmap.GetSize().y);

UVList.push_back((charRect.x + charRect.z ) / bitmap.GetSize().x);
UVList.push_back((charRect.y + charRect.w) / bitmap.GetSize().y);

disp += charRect.z;
}

glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, VertexList.size() * sizeof(GLfloat), &VertexList[0], GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glBufferData(GL_ARRAY_BUFFER, UVList.size() * sizeof(GLfloat), &UVList[0], GL_STATIC_DRAW);

Model = glm::translate(Pos.x/winS.x , Pos.y/winS.y, 0.0f);
MVP = SOGLF::Matrices::Matrix.GetOrthogonal() * Model;
}


I dont get any errors, or anything. Simply nothing displays.
I tried changing the shader so that it would just dsplay a black vertex but nothing showed up either.

38. OK so I think I have everything setup so that it should draw... but it doesnt.
Talk to me on steam or gmail chat (naelstrof@gmail.com); I develop on Linux as well and can help you out.
I find forums an uncomfortable place to help you when you have so many questions and so much code.

39. Talk to me on steam or gmail chat (naelstrof@gmail.com); I develop on Linux as well and can help you out.
I find forums an uncomfortable place to help you when you have so many questions and so much code.
Y'know for someone posting in the programmers section, you should really realize how easy it is to write a web scraper for emails.
Agree x 1 Optimistic x 1 (list)

40. I want to chat with him; I do not want to use email or forums.