I'm been writing some code in Code::Blocks, and I've wondered, when debugging, is there a way to view the child object information. Like in VS when you debug, you can view object data.
I want to start with my procedural planet generator, but im not sure how I should do this.
Do I:
Create a HUGE flat plane,
Use some form of noise to give it some height
then turn that plane into a cube
then turn that cube into a ball
In SFML, if you move or resize the renderwindow, the program locks up as moving or resizing is an event and is repeatedly polled. Is there a way to do this in the background? Because it prevents packets from being sent from the client to the server, and the server thinks the client has DC'd. I think I have to use threads, which I am not familiar with and have no idea how I would go about doing it.
[QUOTE=Richy19;35615033]I want to start with my procedural planet generator, but im not sure how I should do this.
Do I:
Create a HUGE flat plane,
Use some form of noise to give it some height
then turn that plane into a cube
then turn that cube into a ball[/QUOTE]
Subdivide/tessellate an icosahedron iteratively. Apply noise ('height' only, distance from center) at each iteration to get multi-frequency perlin-like noise. You can apply a non-linear function at the end to rescale things a bit and produce more natural-looking features. i.e. compress low areas into 'plains', exaggerate high areas into mountain peaks, etc.
Meanwhile in processing... I am getting this fun little error.
[code]
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PApplet.stroke(Unknown Source)
at Planet.draw(Planet.java:39)
at SolarSystem.draw(SolarSystem.java:100)
at start.draw(start.java:24)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
[/code]
Here is my planet class that i am trying to have it draw its self.
[code]
import processing.core.*;
class Planet extends SpaceObj{
private static final long serialVersionUID = 1L;
int raidus;
private String name;
PVector vector;
PVector cords;
public Planet(String nameIn, PVector cordsIn, PVector vectorIn,int raidusIn){
name = nameIn;
cords = cordsIn;
vector = vectorIn;
raidus = raidusIn;
}
public String getName(){
return this.name;
}
public PVector getVector(){
return this.vector;
}
public PVector getCords(){
return this.cords;
}
public int getSizeS(){
return this.raidus;
}
public void setNewVector(PVector vectorIn){
vector = vectorIn;
}
public void draw(){
System.out.println(cords);
pa.stroke(200);
pa.ellipse(cords.x,cords.y,raidus,raidus);
}
}
[/code]
This is my super class spaceobj class. I am using it to hold a bunch of different objects in space (as the name suggests)
[code]
import processing.core.*;
public abstract class SpaceObj extends PApplet {
private static final long serialVersionUID = 1L;
PApplet pa = new PApplet();
PGraphics pg = new PGraphics();
public SpaceObj(){
}
public PVector getVector() {
return this.getVector();
}
public String getName(){
return this.getName();
}
public PVector getCords(){
return this.getCords();
}
public int getSizeS(){
return this.getSizeS();
}
public void setNewVector(PVector vectorIn){
this.setNewVector(vectorIn);
}
public void draw(){
draw();
}
}
[/code]
When I call the SpaceObj.draw(); it gives me the error message that I posted at the top. I have no clue what it might be, but when i replace "PApplet pa = new PApplet();" with "PGraphics pg = new PGraphics();" I don't get the error but the ellipse isn't drawn. Any one have a idea for a fix?
I have to make a chat program, so you go into console and you write your name and connect and then everybody who is connected can see the chat.
What is the best way of doing this? We have a program that connects to a localhost server and then you run the client in terminal and whatever you write will get echoed back to you, where should we go from here?
[QUOTE=WTF Nuke;35615461]In SFML, if you move or resize the renderwindow, the program locks up as moving or resizing is an event and is repeatedly polled. Is there a way to do this in the background? Because it prevents packets from being sent from the client to the server, and the server thinks the client has DC'd. I think I have to use threads, which I am not familiar with and have no idea how I would go about doing it.[/QUOTE]
You probably will have to use a thread, they're easy enough once you understand mutexes and stuff. Basically, you should try and keep as few variables shared between threads as possible, and use mutexes to ensure they are not accessed at the same time.
[URL]http://www.sfml-dev.org/tutorials/1.2/system-threads.php[/URL]
Basically you just create your mutex(es), and do something this in threads:
[code]
//thread 1
mutex.lock();
myVector.push_back(myObject);
mutex.unlock();
//thread 2
mutex.lock();
object obj = myVector[i];
obj.doThing();
mutex.unlock();
[/code]
when a mutex is locked in one thread, other threads wait until it's unlocked then lock it themselves and do their own operations. Each thread gains exclusive control of anything affected by that mutex when it locks it.
Hey guys. I'm working on a Minecraft style voxel engine... thing, and I've encountered a problem where if I try to draw too many cubes my performance drops dramatically. I'm thinking its because I'm not using Vertex Buffer Objects. Problem is I have very little understanding of what they are and how they work. If anyone could point me in the right direction for an easy to understand explanation or even some tutorial on how to implement it into openGL I'd greatly appreciate it :) By the way I'm using LWJGL
Just for the sake of making my post less dull, here's a screenshot :D
[IMG]http://img256.imageshack.us/img256/4663/wip1a.png[/IMG]
[QUOTE=tommo120;35621358]Hey guys. I'm working on a Minecraft style voxel engine... thing, and I've encountered a problem where if I try to draw too many cubes my performance drops dramatically. I'm thinking its because I'm not using Vertex Buffer Objects. Problem is I have very little understanding of what they are and how they work. If anyone could point me in the right direction for an easy to understand explanation or even some tutorial on how to implement it into openGL I'd greatly appreciate it :) By the way I'm using LWJGL
Just for the sake of making my post less dull, here's a screenshot :D
[IMG]http://img256.imageshack.us/img256/4663/wip1a.png[/IMG][/QUOTE]
A huge optimisation is to only draw the faces that are actually possible to be seen; i.e ones that are touching 'air'. And yes, throwing all that into a VBO will help.
[QUOTE=Chris220;35621684]A huge optimisation is to only draw the faces that are actually possible to be seen; i.e ones that are touching 'air'. And yes, throwing all that into a VBO will help.[/QUOTE]
Do you know what could help me with my problem?
I create the vertex points:
[cpp]int l = 1024;
for(int x = (l/2) * -1; x < (l/2); x++)
{
for(int y = (l/2) * -1; y < (l/2); y++)
{
vertex_data.push_back(glm::vec3( x, 0.0f, y));
vertex_data.push_back(glm::vec3( x, 0.0f, y+1));
vertex_data.push_back(glm::vec3( x+1, 0.0f, y));
vertex_data.push_back(glm::vec3( x+1, 0.0f, y));
vertex_data.push_back(glm::vec3( x, 0.0f, y+1));
vertex_data.push_back(glm::vec3( x+1, 0.0f, y+1));
}
}[/cpp]
Then create the buffers:
[cpp]glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, vertex_data.size() * sizeof(glm::vec3), &vertex_data[0], GL_STATIC_DRAW);
glGenBuffers(1, &uvbuffer);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glBufferData(GL_ARRAY_BUFFER, uv_data.size() * sizeof(glm::vec2), &uv_data[0], GL_STATIC_DRAW);
glGenBuffers(1, &normbuffer);
glBindBuffer(GL_ARRAY_BUFFER, normbuffer);
glBufferData(GL_ARRAY_BUFFER, norm_data.size() * sizeof(glm::vec3), &norm_data[0], GL_STATIC_DRAW);
MatrixID = glGetUniformLocation(shader->shaderID, "MVP");
DrawLinesID = glGetUniformLocation(shader->shaderID, "DrawLines");
textureID = glGetUniformLocation(shader->shaderID, "myTexture");
positionID = glGetAttribLocation(shader->shaderID, "Position");
uvID = glGetAttribLocation(shader->shaderID, "UV");
normID = glGetAttribLocation(shader->shaderID, "Normals");[/cpp]
And finally draw it:
[cpp]glUseProgram(shader->shaderID);
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
glUniform1i(DrawLinesID, prog->drawLines);
glActiveTexture(GL_TEXTURE0);
texture.bind();
glUniform1i(textureID, 0);
// 1rst attribute buffer : vertices
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
);
// 1rst attribute buffer : vertices
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
);
glEnableVertexAttribArray(normID);
glBindBuffer(GL_ARRAY_BUFFER, normbuffer);
glVertexAttribPointer(
normID, // 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
);
// Draw the triangle !
// Index buffer
glDrawArrays(GL_TRIANGLES, 0, vertex_data.size());
glDisableVertexAttribArray(positionID);
glDisableVertexAttribArray(uvID);
glDisableVertexAttribArray(normID);[/cpp]
But the FPS is stupidly low, I dont know if this is because of some sort of optimisation isnt made or just my computer is shit
Oh I have enabled
[cpp]glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);[/cpp]
Oh and is it normal that it slows down alot more if I draw things as GL_LINE?
And another thing if anyone can help me out, I have to choose my modules for next year, the options are:
DATABASES AND INFORMATION RETRIEVAL
HUMAN COMPUTER INTERFACES AND VISUALISATION
WEB APPLICATION PROGRAMMING
ARTIFICIAL INTELLIGENCE
ROBOTICS
COMPUTER GAME DESIGN
COMPUTER GAME PROGRAMMING
C++ PROGRAMMING
OPERATING SYSTEMS
COMPUTER AND DATA NETWORKS
COMPUTER SECURITY
C PROGRAMMING AND EMBEDDED SYSTEMS
Out of which I choose 4, I am pretty sure im going to go for the C and the C++ modules, but I dont know what other ones to choose.
Oh and the games programming one is in XNA and only 2D, which by the sounds of would mmean its the same as what I did in college which would mean I could pass it easily but I wouldnt learn much
How do I build an XNA game, so that someone that doesn't got XNA can use it?
I have a build, it works and all for me. But when I send it to someone, it won't start. So I am guessing it is, because they're lacking XNA.
[QUOTE=IAmAnooB;35622789]How do I build an XNA game, so that someone that doesn't got XNA can use it?
I have a build, it works and all for me. But when I send it to someone, it won't start. So I am guessing it is, because they're lacking XNA.[/QUOTE]
You should just tell them to get the redist runtime really. It's only little: [url]http://www.microsoft.com/download/en/details.aspx?id=20914[/url]
What's the best IDE to program C++ in? At the moment I am using Code Blocks but I can't get rid of it printing "Press any key to continue" and the runtime every time a program ends, and I don't want that in the final program.
[QUOTE=Over-Run;35623241]What's the best IDE to program C++ in? At the moment I am using Code Blocks but I can't get rid of it printing "Press any key to continue" and the runtime every time a program ends, and I don't want that in the final program.[/QUOTE]
It won't be. If you run the executable outside of C::B, you won't get the "Press any key to continue."
[QUOTE=Chris220;35623340]It won't be. If you run the executable outside of C::B, you won't get the "Press any key to continue."[/QUOTE]
Oh cool I found it thanks a lot! I have another problem. I am doing a project for college where I have to make a games compendium. So I am working on the main menu in the terminal, but for some reason after any choice the program exits. Anybody know how I could solve this?
Code is here: [url]http://pastebin.com/LTxESaKL[/url]
[QUOTE=Over-Run;35623516]Oh cool I found it thanks a lot! I have another problem. I am doing a project for college where I have to make a games compendium. So I am working on the main menu in the terminal, but for some reason after any choice the program exits. Anybody know how I could solve this?
Code is here: [url]http://pastebin.com/LTxESaKL[/url][/QUOTE]
Anything that is cin returns a string not an int, all of your comparisons are comparing an int and a string which will always be false.
Cheers for the response. How do I fix that so it returns the int the user puts in.
When I choose any of the options I can see it print the next screen but it closes immediately then.
[QUOTE=Over-Run;35623686]Cheers for the response. How do I fix that so it returns the int the user puts in.
When I choose any of the options I can see it print the next screen but it closes immediately then.[/QUOTE]
Just change all your comparaisons from ints to strings, so:
if(choice == 1)
to
if(choice == '1')
That just makes the program quit after any choice, it doesn't even print the next screen just exits.
[QUOTE=Richy19;35623649]Anything that is [B]cin returns a string not an int[/B], all of your comparisons are comparing an int and a string which will always be false.[/QUOTE]
Nope! cin gives the type you want. For example
[code]int choice;
cin >> choice;[/code]
That's totally correct and reads in an int properly.
Oh shit, my bad. your code was right.
Ahh right I see the problem.
you have cout << "\n\nPress 1 to return"; at the end of each function, yet nothing to check user input after it
So what is the problem with it?
[QUOTE=Over-Run;35624034]So what is the problem with it?[/QUOTE]
To make it stay at that point you need something like:
cin.get();
In c++, what does it mean if a reference is ambiguous? I did everything right according to the people at stackoverflow and it still gives me this error.
It means it can resolve to several objects
[editline]18th April 2012[/editline]
Or things in general, not just objects I guess?
What's the correct syntax for inheriting constructors in C++?
The following does not work.
GameState.h (Parent)
[cpp]class GameState
{
public:
GameState();
virtual void Initialize() = 0;
virtual bool Load() = 0;
virtual void Update(GLdouble time) = 0;
virtual void Draw() = 0;
virtual void Exit() = 0;
};[/cpp]
MenuState.h (Child)
[cpp]class MenuState : public GameState
{
public:
MenuState() : GameState() { }
virtual void GameState::Initialize();
virtual bool GameState::Load();
virtual void GameState::Update(GLdouble time);
virtual void GameState::Draw();
virtual void GameState::Exit();
};[/cpp]
There is also MenuState.cpp, but I'm not sure whether or not I'll need to do anything there?
[QUOTE=Mordi;35626235]What's the correct syntax for inheriting constructors in C++?
The following does not work.
GameState.h (Parent)
[cpp]class GameState
{
public:
GameState();
virtual void Initialize() = 0;
virtual bool Load() = 0;
virtual void Update(GLdouble time) = 0;
virtual void Draw() = 0;
virtual void Exit() = 0;
};[/cpp]
MenuState.h (Child)
[cpp]class MenuState : public GameState
{
public:
MenuState() : GameState() { }
virtual void GameState::Initialize();
virtual bool GameState::Load();
virtual void GameState::Update(GLdouble time);
virtual void GameState::Draw();
virtual void GameState::Exit();
};[/cpp]
There is also MenuState.cpp, but I'm not sure whether or not I'll need to do anything there?[/QUOTE]
What... why are you putting "GameState::" before all the function names in MenuState??
How can I store a float in a unsigned char [4]? I don't need much precision on both the decimals and the whole numbers, so 2 bytes for each.
[cpp]
char dst[4];
float src;
*((float*)dst) = src;
[/cpp]
??
If you're planning to write this to a file or send it over a network or whatever, you'll need to flip the bytes around, though.
Wow thanks, but how does that work? By flip do you mean src= *((float*)dst)?
Sorry, you need to Log In to post a reply to this thread.