[QUOTE=Siemens;26795370]You need a : after the def one().
Also, I would advise against including the filename as a comment. It's just redundant.[/QUOTE]
Thanks. The book I'm reading is using it, so.... I don't wanna mess anything up.
[QUOTE=Johnbooth;26795401]Thanks. The book I'm reading is using it, so.... I don't wanna mess anything up.[/QUOTE]
Then it's a shit book, stop reading it now.
I agree it looks terrible, why are you indentations so high as well? Try 4 spaces or something it will look nicer. If you want a good python tutorial then: [url]http://docs.python.org/tutorial/[/url] will get you started.
The book probably shows the filename as a comment so you can relate it to any source code they might provide electronicly.
[QUOTE=Kagrenak;26781040]Not directly a programming issue, but it definitely doesn't need its own thread;
Is there any sort of reference to F# that doesn't assume you have more than a year or two of other programming experience? Or is it just a bad idea to learn it when you don't know very much about programming in general?[/QUOTE]
F# has the distinction of not having much academic support behind it unlike other FP languages, so I assume the introductory-course market is virtually nil. If you need to learn one, go for Haskell (huge type-theoretic academic community) or Scheme (huge academic programming-language theory community).
has anyone used this? [url]http://www.luminance.org/code/2009/06/17/tiled-map-loader-for-xna[/url]
for loading tiled files into XNA?
When i run my project it compiles fine but gives the error in the tiled.cs file
on
while (reader.Read())
with error:
An error has occurred while opening external DTD 'http://mapeditor.org/dtd/1.0/map.dtd': Unable to connect to the remote server
Ii even tryed to download the map.dtd file and try to integrate it into my project directly but it wont load :/
Ughh, the example program runs fine, both map files are multilayer. so i dont know what it is thats making this fail
Got it to work by removing
<!DOCTYPE map SYSTEM "http://mapeditor.org/dtd/1.0/map.dtd">
from the tiled file
[url]http://cpp.pastebin.com/yHFLcLhc[/url]
Ok, so I finally got a basic triangle rendering using no deprecated code (I hope). Took me far longer than I expected, but there you go.
How would I go about adding a colour for each vertex? I can't figure out how I can put colour data into the same VBO and tell OpenGL how to use it
Edit: Oh yeah, and... why is my triangle upside-down?
[QUOTE=bootv2;26808625]How do I load multiple sprites from a single image with different locations in the image? the image is my tileset. this is in sfml 2.0.
and how do I draw a single sprite multiple times? I've been searching for it and I think I'm just being dumb not seeing how to do both of these.[/QUOTE]
K so how are your sprites stored? Is it a class or something? You should use a static image so that you only load it once, and then make a function that sets the SubRectangle of the sprite. To draw a sprite multiple times just call Draw() multiple times.
Trying to follow a C++ tutorial to start basic multiplayer coding but each example just doesn't want to work. The code builds perfectly fine but when I run them both there appears to be no interaction at all.
Due to the tutorial being a pay to see I don't think it would be fair of me to post it up on here, so I will just post the classes.
Here is the code for the client.
[code]
#define _WINSOCKAPI_ // Don't include Winsock.h
#include <winsock2.h> // WinSock header file
#include <stdio.h> // Input/Output header file for gets() function
#pragma comment(lib, "Ws2_32.lib") // WinSock Library
#define SERVER_ADDRESS "192.168.1.100"
#define SERVER_PORT 17000
WSADATA Winsock; // Stores information about Winsock
SOCKET Socket; // The ID of the socket
sockaddr_in ServerAddress; // The address to send data to
char Buffer[16]; // The buffer of data to send
void main()
{
WSAStartup(MAKEWORD(2, 2), &Winsock); // Start Winsock
if(LOBYTE(Winsock.wVersion) != 2 || HIBYTE(Winsock.wVersion) != 2) // Check version
{
WSACleanup();
return;
}
// Make the Socket
Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
// Input Server Information
ZeroMemory(&ServerAddress, sizeof(ServerAddress)); // clear the struct
ServerAddress.sin_family = AF_INET; // set the address family
ServerAddress.sin_addr.s_addr = inet_addr(SERVER_ADDRESS); // set the IP address
ServerAddress.sin_port = SERVER_PORT; // set the port
// Send the Messages
while(true)
{
gets(Buffer);
sendto(Socket, Buffer, 16, 0, (sockaddr*)&ServerAddress, sizeof(sockaddr));
if(Buffer[0] == ' ')
break;
}
WSACleanup(); // Close Winsock before exiting
return;
}
[/code]
and here is the code for the server.
[code]
#define _WINSOCKAPI_ // Don't include Winsock.h
#include <winsock2.h> // WinSock header file
#include <stdio.h> // Input/Output header file for gets() function
#pragma comment(lib, "Ws2_32.lib") // WinSock Library
//#define SERVER_ADDRESS "192.168.1.100" // no longer needed
#define SERVER_PORT 17000
WSADATA Winsock;
SOCKET Socket;
sockaddr_in ServerAddress;
sockaddr_in IncomingAddress; // the client's address
char Buffer[16];
int AddressLen = sizeof(IncomingAddress); // the size of the client's address
void main()
{
WSAStartup(MAKEWORD(2, 2), &Winsock); // Start Winsock
if(LOBYTE(Winsock.wVersion) != 2 || HIBYTE(Winsock.wVersion) != 2) // Check version
{
WSACleanup();
return;
}
// Make the Socket
Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
// Input server information and bind it to the socket
ZeroMemory(&ServerAddress, sizeof(ServerAddress)); // clear the struct
ServerAddress.sin_family = AF_INET; // set the address family
//ServerAddress.sin_addr.s_addr = inet_addr(SERVER_ADDRESS); // no longer needed
ServerAddress.sin_port = SERVER_PORT; // set the port
bind(Socket, (sockaddr*)&ServerAddress, sizeof(ServerAddress));
while(true)
{
if(recvfrom(Socket, Buffer, 16, 0, (sockaddr*)&IncomingAddress, &AddressLen))
{
Buffer[15] = '\0'; // end the string with a \0
printf("Received: %s\n", Buffer); // show the data on the screen
if(Buffer[0] == ' ')
break;
}
}
WSACleanup(); // Close Winsock before exiting
return;
}
[/code]
[QUOTE=Chris220;26807650][url]http://cpp.pastebin.com/yHFLcLhc[/url]
Ok, so I finally got a basic triangle rendering using no deprecated code (I hope). Took me far longer than I expected, but there you go.
How would I go about adding a colour for each vertex? I can't figure out how I can put colour data into the same VBO and tell OpenGL how to use it
Edit: Oh yeah, and... why is my triangle upside-down?[/QUOTE]
Anyone?
Edit: Only three posts in between these? I feel like a dick now :frown:
Ok ignore my last question, I'm trying something different now:
[code]#include <iostream>
#include <SFML/Graphics.hpp>
#define GLEW_STATIC
#include <GL/glew.h>
#include "math3d.h"
void LogErrors()
{
GLenum err;
while((err = glGetError()) != GL_NO_ERROR)
{
switch(err)
{
case(GL_INVALID_ENUM):
std::cerr << "GL_INVALID_ENUM" << std::endl;
break;
case(GL_INVALID_VALUE):
std::cerr << "GL_INVALID_VALUE" << std::endl;
break;
case(GL_INVALID_OPERATION):
std::cerr << "GL_INVALID_OPERATION" << std::endl;
break;
case(GL_STACK_OVERFLOW):
std::cerr << "GL_STACK_OVERFLOW" << std::endl;
break;
case(GL_STACK_UNDERFLOW):
std::cerr << "GL_STACK_UNDERFLOW" << std::endl;
break;
case(GL_OUT_OF_MEMORY):
std::cerr << "GL_OUT_OF_MEMORY" << std::endl;
break;
case(GL_TABLE_TOO_LARGE):
std::cerr << "GL_TABLE_TOO_LARGE" << std::endl;
break;
}
}
}
// Utility function to simply build a data buffer
GLuint BuildBuffer(GLenum Target, const void *BufferData, GLsizei BufferSize)
{
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(Target, buffer);
glBufferData(Target, BufferSize, BufferData, GL_STATIC_DRAW);
glBindBuffer(Target, 0);
return buffer;
}
// Utility function to build a texture buffer
GLuint BuildTexture(const sf::Image &Image)
{
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Image.GetWidth(), Image.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, Image.GetPixelsPtr());
glBindTexture(GL_TEXTURE_2D, 0);
return texture;
}
void TestShader(GLuint Shader)
{
GLint compileStatus;
glGetShaderiv(Shader, GL_COMPILE_STATUS, &compileStatus);
if(compileStatus == GL_TRUE) return;
GLint logSize;
glGetShaderiv(Shader, GL_INFO_LOG_LENGTH, &logSize);
GLchar *log = new GLchar[logSize];
glGetShaderInfoLog(Shader, logSize, NULL, log);
std::cerr << log << std::endl;
delete[] log;
}
void TestProgram(GLuint Program)
{
GLint linkStatus;
glGetProgramiv(Program, GL_LINK_STATUS, &linkStatus);
if(linkStatus == GL_TRUE) return;
GLint logSize;
glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &logSize);
GLchar *log = new GLchar[logSize];
glGetProgramInfoLog(Program, logSize, NULL, log);
std::cerr << log << std::endl;
delete[] log;
}
// Utility function to compile a shader
GLuint BuildShader(GLenum Type, const char *Code)
{
GLuint shader = glCreateShader(Type);
if(shader == 0)
{
std::cerr << "An error occurred while creating a new shader" << std::endl;
LogErrors();
return 0;
}
glShaderSource(shader, 1, &Code, NULL);
glCompileShader(shader);
TestShader(shader);
return shader;
}
// Utility function to link a shader program
GLuint BuildProgram(GLuint VertShader, GLuint FragShader)
{
GLuint program = glCreateProgram();
if(program == 0)
{
std::cerr << "An error occurred while creating a new shader program" << std::endl;
LogErrors();
return 0;
}
glAttachShader(program, VertShader);
glAttachShader(program, FragShader);
glLinkProgram(program);
TestProgram(program);
return program;
}
int main()
{
// Initialise GLEW
glewInit();
const GLfloat W = 800.0f;
const GLfloat H = 600.0f;
sf::Window window(sf::VideoMode(W, H), "Non-deprecated OpenGL", sf::Style::Close);
bool keys[sf::Key::Count];
// Set up some buffer indices
GLuint vertexBuffer, elementBuffer;
GLuint textureBuffer;
GLfloat screenQuadVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f
};
GLushort screenQuadIndices[] = { 0, 1, 2, 3 };
vertexBuffer = BuildBuffer(GL_ARRAY_BUFFER, screenQuadVertices, sizeof(screenQuadVertices));
elementBuffer = BuildBuffer(GL_ARRAY_BUFFER, screenQuadIndices, sizeof(screenQuadIndices));
sf::Image image;
image.LoadFromFile("test.png");
textureBuffer = BuildTexture(image);
// Now create some basic shaders
const GLchar *vertShaderCode =
"#version 140\n"
"in vec2 position;\n"
"out vec2 texcoord;\n"
"void main()\n"
"{\n"
"gl_Position = vec4(position, 0.0, 1.0);\n"
"texcoord = (position + 1.0) * 0.5;\n"
"}\n";
const GLchar *fragShaderCode =
"#version 140\n"
"in vec2 texcoord;\n"
"uniform sampler2D texture;\n"
"void main()\n"
"{\n"
"//gl_FragColor = texture2D(texture, texcoord);\n"
"gl_FragColor = vec4(0.5, 1.0, 0.0, 1.0);\n"
"}\n";
GLuint vertShader = BuildShader(GL_VERTEX_SHADER, vertShaderCode);
GLuint fragShader = BuildShader(GL_FRAGMENT_SHADER, fragShaderCode);
GLuint shaderProgram = BuildProgram(vertShader, fragShader);
GLuint positionLoc = glGetUniformLocation(shaderProgram, "position");
GLuint textureLoc = glGetUniformLocation(shaderProgram, "texture");
while(window.IsOpened())
{
sf::Event e;
while(window.GetEvent(e))
{
switch(e.Type)
{
case(sf::Event::Closed):
window.Close();
break;
case(sf::Event::KeyPressed):
if(e.Key.Code == sf::Key::Escape)
window.Close();
else
keys[e.Key.Code] = true;
break;
case(sf::Event::KeyReleased):
keys[e.Key.Code] = false;
break;
default:
break;
}
}
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Activate our shader program
glUseProgram(shaderProgram);
// Activate the first texture unit
glActiveTexture(GL_TEXTURE0);
// Bind our texture to it
glBindTexture(GL_TEXTURE_2D, textureBuffer);
// Upload it to the fragment shader (The zero just means to use the first texture unit)
glUniform1i(textureLoc, 0);
// Now activate our vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
// Enable the vertex attribute array
glEnableVertexAttribArray(positionLoc);
// Point the "position" input of the shader to our vertex buffer
glVertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, 0);
// Bind the element/index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
// Now draw the elements in the order specified in the element buffer
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, 0);
window.Display();
}
return 0;
}[/code]
Following this ([url]http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-1:-The-Graphics-Pipeline.html[/url]) tutorial, I'm trying to get a textured quad up on the screen.
I've checked over my code a few times, and I can't figure out why it isn't drawing
a = raw_input("Enter first name: ")
b = raw_input("Enter last name: ")
name = (a + b)
print "Hello, " [b]name[/b] ". Or should I call you Mr. " b "?"
Python says "name" is an invalid syntax when I defined it the very line before it.
[QUOTE=Raneman;26825032]a = raw_input("Enter first name: ")
b = raw_input("Enter last name: ")
name = (a + b)
print "Hello, " [b]name[/b] ". Or should I call you Mr. " b "?"
Python says "name" is an invalid syntax when I defined it the very line before it.[/QUOTE]
It's invalid syntax because you didn't concatenate it with the strings.
[code]print "Hello, " + name + ". Or should I call you Mr. " + b + "?"[/code]
Another option is to use string formatting.
[code]print "Hello, %s. Or should I call you Mr. %s?" % (name, b)[/code]
Thanks. I figured that out right before you posted. But now when I enter my first name it says that name is not defined.
[QUOTE=bootv2;26825535]Subretangle doesn't work on images. so I tried setting one sprite as the tileset image. then get the subrect of that sprite and set that to other sprites. which doesn't work since a sprite cannot be set with the image of a sprite.[/QUOTE]
Store a list of sprites using the same image and set the correct subrect on each of them.
[editline]20th December 2010[/editline]
Or am I misunderstanding what you're trying to do?
I don't need to go too in depth, but I am working purely with text. How would I get a command that when used on an object produces a context sensitive text result? Example: Kick Disposal Unit
[QUOTE=Raneman;26826079]I don't need to go too in depth, but I am working purely with text. How would I get a command that when used on an object produces a context sensitive text result? Example: Kick Disposal Unit[/QUOTE]
Well, usually in text adventures commands are "<verb> <noun>". As such, search for objects in the inventory or current location that are named <noun> and then pass the <verb>-string into some function (e.g. handlePlayerInteraction(string verb)), where you could have simple switch.
Some commands might have two nouns, e.g. when giving something to someone. The command might be "give <noun1> to <noun2>". Here you can simply split the string at "to" and pass "give <noun1>" to an object names <noun2>. This would require a special function (e.g. handleComplexInteraction(string interaction)) or simply as a special case in the same function as before (handlePlayerInteraction(string verb), since the passed string ("give <noun1>") must be split yet again by the function to obtain the verb.
That said, I'm not too clear this is actually the information you requested. If it was not, be more specific and tell us what you have working already.
[QUOTE=bootv2;26826040]I'm just guessing the whole tileset gets loaded every time it's used in a sprite.[/QUOTE]
It won't, that's the whole point of the separation of sprites and images.
[QUOTE=bootv2;26826623]doing this will somehow show a way too large part of the tileset. even a 1x1 subrect will end up at at least 50x20 and somehow this doesn't happen with sf::IntRect(0,0,10,10) but does with sf::IntRect(161, 60, 177, 76)[/QUOTE]
That's weird, I don't know, check the documentation I guess.
[QUOTE=bootv2;26828884]okay good to know it won't be loaded multiple times. and maybe I've encountered my first sfml2.0 bug.
[editline]20th December 2010[/editline]
I've fixed it, apparently sfml reads the size of a tile in the image, how I don't know but increasing the pixel with one in the width increases the tile with one.[/QUOTE]
Can you post your code? I can't understand what's wrong, everything works fine for me. Why do you want to have the same sprite drawn twice anyway? And this is what I meant before. Have a class with a static sf::Image. Then set every sprite to use that image, but change their own subrects. The subrect is like this (x co-ord, y co-ord, width, height).
[QUOTE=bootv2;26829467][cpp]if (App.GetInput().IsKeyDown(sf::Key::A)) Grass.Move(-100.f*ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::D)) Grass.Move( 100.f*ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::W)) Grass.Move(0, -100.f*ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::S)) Grass.Move(0, 100.f*ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::R)) Grass.SetPosition(200.5f, 100.5f);
if (App.GetInput().IsKeyDown(sf::Key::Escape)) App.Close();
if (App.GetInput().IsKeyDown(sf::Key::Q)) Grass.Rotate(-300.f*ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::E)) Grass.Rotate( 300.f*ElapsedTime);[/cpp][/QUOTE]
Oh, hi nullsquared
I'm kidding, of course. If you want those grass images to tile, you'll want to draw them more than once, right?
So just stick a for loop in there, move the sprite and draw it on each iteration of the loop.
Well first thing is you should find how many grass tiles you want in each direction. From then make a simple for loop, something like this:
[cpp]for(int y = 0; y < windowheight / Grass.height(); y++){
for(int x = 0; x < windowlength / Grass.length(); x ++){
Grass.SetPosition(x * Grass.length(), y * Grass.height;
}
}
[/cpp]
[QUOTE=bootv2;26830047]I know that. I just want to know why the setsubrect command won't work properly. that it sets 1 pixel as a tile was just a coincidence since all the other tiles get more than one tile onscreen with that one pixel. I'd really like a solution to that since I'm thinking I'm doing something very stupid, I just can't see what it is.[/QUOTE]
As I said, it measures the height and length from a certain co-ordinat. So a 1 by 1 subrect at location 53,32 would be (53, 32, 1, 1)
[QUOTE=bootv2;26829467][img_thumb]http://i56.tinypic.com/2wdseq1.png[/img_thumb][/QUOTE]
Mag wel iets leesbaarder.
Programming is great and all, but how do I use graphics? Just a tile based game with no animations would suffice for my needs.
Im trying to create a RenderTarget2D in XNA but i keep getting errors, i think its because i ont know what to put in as the format:
[code]RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width + 80, GraphicsDevice.Viewport.Height + 80, 1, SurfaceFormat.Rgba32);[/code]
I tried surfacedormat.color which i think is the one i need to use, but i get this with spritebatch.end
[quote]The active render target and depth stencil surface must have the same pixel size and multisampling type.[/quote]
For some reason, after adding something to my code and compiling, the program hangs at the console window. It doesn't make a SFML display or anything. Anyone know why this could be?
I'm assuming it worked before, so let's try the obvious right now. Try restarting your IDE / computer, I've had issues with Eclipse / Android emulator where simply restarting it got rid of some strange bugs.
[editline]21st December 2010[/editline]
also, try removing what you added, see if it works again. If it doesn't, well, there's your problem.
[QUOTE=bootv2;26832790]was nog voor een vriend die aan het grafische gedeelte werkt.
ik vind het wel een leuk lettertype voor dialogen, en zo erg is het toch niet?[/QUOTE]
Ligt aan de grootte denk ik.
[QUOTE=robmaister12;26844972]I'm assuming it worked before, so let's try the obvious right now. Try restarting your IDE / computer, I've had issues with Eclipse / Android emulator where simply restarting it got rid of some strange bugs.
[editline]21st December 2010[/editline]
also, try removing what you added, see if it works again. If it doesn't, well, there's your problem.[/QUOTE]
No, it still doesn't work. All the change effects is the inventory. Wait, I have an idea.
[editline]21st December 2010[/editline]
Seems to be a problem with my card. Just updated ATi drivers, and now no SFML apps work.
hmm, well that's certainly an issue. try running [url]http://www.guru3d.com/category/driversweeper/[/url], then reinstall your graphics drivers, maybe that'll fix it...
Sorry, you need to Log In to post a reply to this thread.