[QUOTE=amazer97;35365268]Can anyone help me with this? I tried to write a function that outputs a hex string from an integer to the screen, but it doesn't seem to be working.
[code]
void monitor_write_hex(u32int n)
{
int i;
u8int hex_char;
for(i = 32; i > 0; i -= 4)
{
hex_char = (n << i) & 0xF;
if(hex_char >= 0xA)
monitor_put((hex_char - 0xA) + 'a');
else
monitor_put(hex_char + '0');
}
}
[/code]
For monitor_write_hex(256) I get "00000000" on the screen. Any tips?[/QUOTE]
[cpp]void monitor_write_hex(u32int n)
{
int i;
u8int hex_char;
for(i = 28; i >= 0; i -= 4)
{
hex_char = (n >> i) & 0xF;
if(hex_char >= 0xA)
monitor_put((hex_char - 0xA) + 'a');
else
monitor_put(hex_char + '0');
}
}[/cpp]
[editline]31st March 2012[/editline]
Wrong bit shifting direction and the shifts were off by 4 bits.
[QUOTE=ThePuska;35366627]
Wrong bit shifting direction and the shifts were off by 4 bits.[/QUOTE]
Thanks, fixed it and it works now! Can you explain why though? Isn't x86 little endian, so if I understand correctly you have to shift to the left to get the most significant bits first in order to print it most to least significant in hex?
As far as I've understood, endianness only matters to how the numbers are stored in memory, not to how you operate on them. Regardless, you can count that shifting right divides an integer by two - this is at the very least ensured by some programming language standards, including the C standards.
[QUOTE=ThePuska;35366950]As far as I've understood, endianness only matters to how the numbers are stored in memory, not to how you operate on them. Regardless, you can count that shifting right divides an integer by two - this is at the very least ensured by some programming language standards, including the C standards.[/QUOTE]
That makes sense then, for some reason I thought that endianness counts in operations too.
[QUOTE=Parad0x0217;35361678]Make sure the texture is a power of 2.[/QUOTE]
Even with a power of 2 it still has artifact.
Can anyone see why this is just drawing a quad and not a cube?
[IMG]http://i.imgur.com/QoKEO.png[/IMG]
[cpp]#include <iostream>
#include <string>
#include <GL/glew.h>
#include <GL/glfw.h>
#include "./Program.hpp"
int main(int argc, const char* argv[])
{
if( !glfwInit() )
{
return 32;
}
// Open an OpenGL window
if( !glfwOpenWindow( 1024, 576, 0,0,0,0,0,0, GLFW_WINDOW ) )
{
glfwTerminate();
return 32;
}
short glReqAA = 2;
short glReqMajor = 2;
short glReqMinor = 1;
double fpsTime = 0.0;
if(60 > 0)
fpsTime = 1.0/60;
glfwOpenWindowHint( glReqAA, GLFW_FSAA_SAMPLES);
glfwOpenWindowHint( 60, GLFW_REFRESH_RATE );
glfwOpenWindowHint( glReqMajor, GLFW_OPENGL_VERSION_MAJOR);
glfwOpenWindowHint( glReqMinor, GLFW_OPENGL_VERSION_MINOR);
glfwSetWindowTitle("OpenGL tech demo");
short glMajor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR);
short glMinor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR);
try{
std::cout << "Using OpenGL " << glMajor << "." << glMinor << std::endl;
if ((glMajor < glReqMajor) || (glMajor == glReqMajor && glMinor < glReqMinor))
{
std::cout << "Sorry but a minimum of OpenGL "<< glReqMajor <<"."<< glReqMinor <<" is required"<<std::endl;
std::cout << "Try updating your drivers." << std::endl;
return 32;
}
}
catch(int e)
{
std::cout << "Failed to get OpenGL version. " << e << std::endl;
return 32;
}
if(true)
{
int width = 0;
int height = 0;
glfwGetWindowSize( &width, &height );
std::cout << "Using resolution: "<< width << "x" << height << std::endl;
}
short glAA = glfwGetWindowParam(GLFW_FSAA_SAMPLES);
if(glReqAA != glAA)
{
std::cout << "Antialiasing Level of " << glReqAA << " was unavailable, using level " << glAA << " instead." << std::endl;
}
GLenum err = glewInit();
if (GLEW_OK != err)
{
// Problem: glewInit failed, something is seriously wrong.
std::cout << "Error: " << glewGetErrorString(err) << std::endl;
glfwTerminate();
return 32;
}
std::cout << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
Program *prog = new Program();
// Ensure we can capture the escape key being pressed below
double delta = glfwGetTime();
glfwSetTime( 1.0/60.0 );
// Enable depth test
glEnable(GL_DEPTH_TEST);
// Accept fragment if it closer to the camera than the former one
glDepthFunc(GL_LESS);
while(!glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED ))
{
prog->Update(delta);
delta = glfwGetTime();
if(fpsTime > 0.0) glfwSleep(delta - fpsTime);
glfwSetTime( 0.0 );
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
prog->Draw();
glfwSwapBuffers();
}
delete prog;
glfwTerminate();
return 0;
}
//*/
//////////////////////////////////////
#ifndef PROGRAM_HPP_INCLUDED
#define PROGRAM_HPP_INCLUDED
#define pointCount 108
#include <glm/glm.hpp>
#include <glm/gtx/transform2.hpp>
#include "./Utilities.hpp"
#include "Shader.hpp"
class Program
{
GLfloat g_vertex_buffer_data[pointCount];
GLuint vertexbuffer;
Shader shader;
glm::mat4 MVP;
GLuint MatrixID;
GLuint positionID;
public:
Program();
~Program();
void Update(float delta);
void Draw();
glm::mat4 Projection;
glm::mat4 View;
};
#endif // PROGRAM_HPP_INCLUDED
///////////////////////////////////////////////
#include "./Program.hpp"
#include "SOIL.h"
Program::Program()
{
//View = glm::mat4(1.0);
View = glm::lookAt(
glm::vec3(1, 1, 3), // the position of your camera, in world space
glm::vec3(0, 0, 0), // where you want to look at, in world space
glm::vec3(0, 1, 0) // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too
);
//Projection = glm::mat4(1.0);
Projection = glm::perspective(
(float)90, // The horizontal Field of View, in degrees : the amount of "zoom". Think "camera lens".
1024.0f / 576.0f, // Aspect Ratio. Depends on the size of your window.
0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues.
100.0f // Far clipping plane. Keep as little as possible.
);
GLfloat fltarr[pointCount]
{
-1.0f,-1.0f,-1.0f, // triangle 1 : begin
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f, // triangle 1 : end
1.0f, 1.0f,-1.0f, // triangle 2 : begin
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f, // triangle 2 : end
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f
};
for(int i = 0; i < pointCount; i++)
{
g_vertex_buffer_data[i] = fltarr[i];
}
// This will identify our vertex buffer
// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbuffer);
// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
// Get a handle for our "MVP" uniform.
// Only at initialisation time.
MatrixID = glGetUniformLocation(shader.shaderID, "MVP");
positionID = glGetAttribLocation(shader.shaderID, "Position");
}
Program::~Program()
{
glDeleteBuffers(1, &vertexbuffer);
}
void Program::Update(float delta)
{
// Model matrix : an identity matrix (model will be at the origin)
glm::mat4 Model = glm::mat4(1.0f); // Changes for each model !
// Our ModelViewProjection : multiplication of our 3 matrices
MVP = Projection * View * Model; //
}
void Program::Draw()
{
GLfloat g_color_buffer_data[] = {
0.583f, 0.771f, 0.014f,
0.609f, 0.115f, 0.436f,
0.327f, 0.483f, 0.844f,
0.822f, 0.569f, 0.201f,
0.435f, 0.602f, 0.223f,
0.310f, 0.747f, 0.185f,
0.597f, 0.770f, 0.761f,
0.559f, 0.436f, 0.730f,
0.359f, 0.583f, 0.152f,
0.483f, 0.596f, 0.789f,
0.559f, 0.861f, 0.639f,
0.195f, 0.548f, 0.859f,
0.014f, 0.184f, 0.576f,
0.771f, 0.328f, 0.970f,
0.406f, 0.615f, 0.116f,
0.676f, 0.977f, 0.133f,
0.971f, 0.572f, 0.833f,
0.140f, 0.616f, 0.489f,
0.997f, 0.513f, 0.064f,
0.945f, 0.719f, 0.592f,
0.543f, 0.021f, 0.978f,
0.279f, 0.317f, 0.505f,
0.167f, 0.620f, 0.077f,
0.347f, 0.857f, 0.137f,
0.055f, 0.953f, 0.042f,
0.714f, 0.505f, 0.345f,
0.783f, 0.290f, 0.734f,
0.722f, 0.645f, 0.174f,
0.302f, 0.455f, 0.848f,
0.225f, 0.587f, 0.040f,
0.517f, 0.713f, 0.338f,
0.053f, 0.959f, 0.120f,
0.393f, 0.621f, 0.362f,
0.673f, 0.211f, 0.457f,
0.820f, 0.883f, 0.371f,
0.982f, 0.099f, 0.879f
};
GLuint colorbuffer;
glGenBuffers(1, &colorbuffer);
glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW);
GLuint colorID = glGetAttribLocation(shader.shaderID, "Color");
// Send our transformation to the currently bound shader,
// in the "MVP" uniform
// For each model you render, since the MVP will be different (at least the M part)
glUseProgram(shader.shaderID);
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][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
);
// 2nd attribute buffer : colors
glEnableVertexAttribArray(colorID);
glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
glVertexAttribPointer(
colorID, // attribute. No particular reason for 1, 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 !
glDrawArrays(GL_TRIANGLES, 0, 12*3); // Starting from vertex 0; 3 vertices total -> 1 triangle
glDisableVertexAttribArray(colorID);
glDisableVertexAttribArray(positionID);
//*/
glDeleteBuffers(1, &colorbuffer);
}[/cpp]
How can I handle velocity? Since I could have multiple velocities with a maximum (so pressing W and say running on something that speeds you up), should I store them all in a container and loop through them and then affect the player's position?
-snip on second part that code wasn't bugged-
Can someone explain to me why does some engines/frameworks use Y as the up vector and other things use Z as up vector?
Does it really matter? And if yes, Why?
Edit: in a 3D game/project
Every id tech based stuff has Z as up vector, but Ogre3D and Minecraft uses Y as up vector.
[QUOTE=ichiman94;35374522]Can someone explain to me why does some engines/frameworks use Y as the up vector and other things use Z as up vector?
Does it really matter? And if yes, Why?[/QUOTE]
Sometimes just preference, but Y is usually up for 2d and Z up for 3d. Doesn't matter at all really.
[QUOTE=ichiman94;35374522]Can someone explain to me why does some engines/frameworks use Y as the up vector and other things use Z as up vector?
Does it really matter? And if yes, Why?[/QUOTE]
It depends on the world you come from. In the math world, when presented with a graph you have two axes, X (horizontal) and Y (vertical). Thus it's a logical extension that when you add a third dimension (depth), there's no reason to re-order your axes, instead you just make Z going into the screen. This causes the world (from top down) to be X/Z, with Y being up/down.
However, some editors (3ds Max) use Z as the up axis, perhaps for the same reason they added Z as depth in an X/Y grid - Just from a top down perspective instead of a side perspective. Games (Source, Quake, etc.) may have followed suit to make asset conversion easier (no flipping the axes on export & dealing with rotation changes), or it may have just been accepted as their up axis.
Doing an assignment for college, was wondering if you guys could check my code and see if everything in it is okay and if there is anything I could improve on?
Basically I just have to solve a bounded buffer problem.
Codes here: [url]http://pastebin.com/yXWnziq3[/url]
Hey guys, can someone tell me how to align text in the console?
I need it like;
[csharp]
/* Sample Output
Kilograms Pounds
20 44.00
40 88.00
60 132.00
80 176.00
100 220.00
120 264.00
140 308.00
160 352.00
180 396.00
200 440.00
*/
[/csharp]
This is my code;
[csharp]public class KiloPoundTable
{
public static void main(String[] args)
{
int kiloCount = 20;
int poundCount = 0;
System.out.println("Kilograms Pounds");
while (kiloCount <= 200)
{
poundCount = (int) (kiloCount * 2.2);
System.out.println(kiloCount + " " + poundCount);
kiloCount+=20;
}
}
}[/csharp]
And this is my output;
[csharp]
Kilograms Pounds
20 44
40 88
60 132
80 176
100 220
120 264
140 308
160 352
180 396
200 440[/csharp]
Unfortunately, when I just add spaces like;
[B] " " + kiloValue +[/B]
It moves it in a weird way because some numbers are 3 digits and others are 2 etc;
Output;
[csharp]
Kilograms Pounds
20 44
40 88
60 132
80 176
100 220
120 264
140 308
160 352
180 396
200 440
[/csharp]
And it basically ruins my pound table.
[QUOTE=WTF Nuke;35377680][cpp]while (kiloCount <= 200)
{
poundCount = (int) (kiloCount * 2.2);
if(kiloCount < 100)
System.out.print(" " + kiloCount);
else
System.out.print(" " + kiloCount);
if(poundCount<100)
System.out.println(" " + poundCount);
else
System.out.println(" " + poundCount);
kiloCount+=20;
}[/cpp][/QUOTE]
Thanks, man! :v:
[editline]1st April 2012[/editline]
Also, I wanted to know how to code the rest of this;
[csharp]
import java.util.Scanner;
public class MaxInput
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
int num = 1;
int count = 1;
int largest = -1;
int firstNum = 0;
System.out.print("Enter the first integer, it can be 0: ");
firstNum = input.nextInt();
if (firstNum == 0)
{
do
{
System.out.print("Enter an integer, or enter '0' to quit: ");
num = input.nextInt();
if (largest < num)
{
largest = num;
count = 1;
}
else if (largest == num)
{
count++;
}
}
while(num != 0);
}
else
{
do
{
System.out.print("Enter an integer, or enter '0' to quit: ");
num = input.nextInt();
if (largest < num)
{
largest = num;
count = 1;
}
if (largest <= firstNum)
{
largest = firstNum;
}
else if (largest == num)
{
// WHAT DO?
}
}
while(num != 0);
}
System.out.println("The largest integer was " + largest + " it occurred " + count + " times. ");
}
}[/csharp]
I'm trying to get it to show me the largest input and how many times it occurs, right?
The problem is this;
[QUOTE]
----OUTPUT----
Enter the first integer, it can be 0: 6
Enter an integer, or enter '0' to quit: 6
Enter an integer, or enter '0' to quit: 6
Enter an integer, or enter '0' to quit: 5
Enter an integer, or enter '0' to quit: 0
The largest integer was 6 it occurred 1 times. [/QUOTE]
It doesn't count properly after I enter a number higher than 0 for firstNum.
Entering 0;
[QUOTE]
---- OUTPUT ----
Enter the first integer, it can be 0: 0
Enter an integer, or enter '0' to quit: 6
Enter an integer, or enter '0' to quit: 6
Enter an integer, or enter '0' to quit: 5
Enter an integer, or enter '0' to quit: 0
The largest integer was 6 it occurred 2 times.
[/QUOTE]
It works if I enter 0, but not if firstNum > 0, at which point the count gets messed up, I think.
Can anyone help me improve, or fix this code? I also think that by repeating the whole loop twice looks wrong, and there must be a more streamlined way of going about it.
One more thing was that the package says 'Use only one return statement and do not use break. Do not have a return in the middle of the main method'.
Which makes it slightly harder.
[QUOTE=WTF Nuke;35377680][cpp]while (kiloCount <= 200)
{
poundCount = (int) (kiloCount * 2.2);
if(kiloCount < 100)
System.out.print(" " + kiloCount);
else
System.out.print(" " + kiloCount);
if(poundCount<100)
System.out.println(" " + poundCount);
else
System.out.println(" " + poundCount);
kiloCount+=20;
}[/cpp][/QUOTE]
I don't mean to criticize your method, but personally I would use format strings for this
[cpp]
public static void main(String[] args) {
int kiloCount = 20;
int poundCount = 0;
System.out.println("Kilograms Pounds");
while (kiloCount <= 200)
{
poundCount = (int) (kiloCount * 2.2);
System.out.printf("%9d %6d\n",kiloCount, poundCount);
kiloCount+=20;
}
}
[/cpp]
Simply for the fact that it takes less thought and fits in one line.
[editline]31st March 2012[/editline]
[QUOTE=Sickle;35377946]Thanks, man! :v:
[editline]1st April 2012[/editline]
Also, I wanted to know how to code the rest of this;
[csharp]
import java.util.Scanner;
public class MaxInput
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
int num = 1;
int count = 1;
int largest = -1;
int firstNum = 0;
System.out.print("Enter the first integer, it can be 0: ");
firstNum = input.nextInt();
if (firstNum == 0)
{
do
{
System.out.print("Enter an integer, or enter '0' to quit: ");
num = input.nextInt();
if (largest < num)
{
largest = num;
count = 1;
}
else if (largest == num)
{
count++;
}
}
while(num != 0);
}
else
{
do
{
System.out.print("Enter an integer, or enter '0' to quit: ");
num = input.nextInt();
if (largest < num)
{
largest = num;
count = 1;
}
if (largest <= firstNum)
{
largest = firstNum;
}
else if (largest == num)
{
// WHAT DO?
}
}
while(num != 0);
}
System.out.println("The largest integer was " + largest + " it occurred " + count + " times. ");
}
}[/csharp]
I'm trying to get it to show me the largest input and how many times it occurs, right?
The problem is this;
It doesn't count properly after I enter a number higher than 0 for firstNum.
Entering 0;
It works if I enter 0, but not if firstNum > 0, at which point the count gets messed up, I think.
Can anyone help me improve, or fix this code? I also think that by repeating the whole loop twice looks wrong, and there must be a more streamlined way of going about it.
One more thing was that the package says 'Use only one return statement and do not use break. Do not have a return in the middle of the main method'.
Which makes it slightly harder.[/QUOTE]
[cpp]
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
int num;
int largest; //The first number is automatically the first largest, so a separate variable is unnecessary
int count = 1;
System.out.print("Enter the first integer, it can be 0: ");
largest = input.nextInt();
System.out.print("Enter an integer, or enter '0' to quit: ");
while((num = input.nextInt()) != 0) { //Simultaneously store and check the new number
if (num == largest) {
count++; //Same number, just increment the count
}
else if (num > largest) {
largest = num;
count = 1; //Higher number, change the largest and reset the count
}
System.out.print("Enter an integer, or enter '0' to quit: ");
}
System.out.printf("The largest integer was %d it occured %d times.", largest, count); //Again, I like format strings, but it's just a personal preference
}
[/cpp]
You made it a bit more complicated than it needed to be. Before you write a block of code, take a second to think your algorithm through. With the exception of a few lines if you find yourself copy and pasting large chunks only to change a couple of things you might want to take a second look at what you are doing.
[QUOTE=Rayjingstorm;35378877]
You made it a bit more complicated than it needed to be. Before you write a block of code, take a second to think your algorithm through. With the exception of a few lines if you find yourself copy and pasting large chunks only to change a couple of things you might want to take a second look at what you are doing.[/QUOTE]
[I][B]Holy shit.[/B][/I] Thanks so much!
That was like fucking magic!
I wish I could code half as well.
[QUOTE=Sickle;35379633][I][B]Holy shit.[/B][/I] Thanks so much!
That was like fucking magic!
I wish I could code half as well.[/QUOTE]
You're welcome and thank you:v:
Again, just take a step back and think about how you would do it at the most basic level. You can work top down to design the layout of your program, but then carefully work bottom up the fill out each block, one by one. If something gets to a point where you have no idea where the problem is originating, and you have expended all of your debugging knowledge, don't be afraid to start over fresh with a new approach: a lot of the time your entire methodology can be faulty.
[QUOTE=Cyril;35361463]I'm trying to make a little game in android, but I have a problem with displaying a sprite.
[img]http://dl.dropbox.com/u/14515180/artifact.png[/img]
The left part of the image is the original sprite and the right is how it's shown in the emulator.
As you can see there is a little artifact. Any idea how to fix it ?[/QUOTE]
OpenGL or Canvas?
[editline]1st April 2012[/editline]
[QUOTE=Parad0x0217;35361678]Make sure the texture is a power of 2.[/QUOTE]
This is good advice regardless, but usually the power of 2 problem causes white boxes, not distortion.
[sp]In C# XNA 4:
I am trying to load a picture from the web into a Texture2D:
[PHP]
SpriteBatch spriteBatch;
Texture2D thetexture; protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
WebRequest req = WebRequest.Create("http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=202528&type=card");
WebResponse response = req.GetResponse();
Stream sstream = response.GetResponseStream();
byte[] imageData = new byte[1048576];
sstream.Read(imageData, 0, 1048576);
MemoryStream stream = new MemoryStream(imageData,0,imageData.Length);
thetexture = Texture2D.FromStream(graphics.GraphicsDevice, stream);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(thetexture, Vector2.Zero, Color.White);
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}[/PHP]
It gives this result:
[IMG]http://dl.dropbox.com/u/15793967/imagenotloading.png[/IMG]
Can anyone help me with this?[/sp]
I have fixed it, and the final function looks like this:
[php] public Texture2D GetCardPicture(int id)
{
Texture2D returntexture;
WebRequest req = WebRequest.Create("http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid="+id+"&type=card");
WebResponse response = req.GetResponse();
Stream sstream = response.GetResponseStream();
byte[] imageData = new byte[1024 * 256];
int bytesread;
int totalbytesread = 0;
//lol = sstream.Read(imageData, 0, imageData.Length);
//lol = sstream.Read(imageData, 0, 1024*128);
while (true)
{
bytesread = sstream.Read(imageData, totalbytesread, imageData.Length - totalbytesread);
totalbytesread += bytesread;
if (bytesread < 1)
break;
}
MemoryStream stream = new MemoryStream(imageData, 0, imageData.Length);
returntexture = Texture2D.FromStream(graphics.GraphicsDevice, stream);
return returntexture;
}[/php]
What is the general process for loading a tga file and an obj file in openGL? I've looked at coding, but I still don't get it yet.
[QUOTE=CoolKingKaso;35390940]What is the general process for loading a tga file and an obj file in openGL? I've looked at coding, but I still don't get it yet.[/QUOTE]
You don't "load" a tga or obj file in OpenGL, as OpenGL only understands raw bitmap data and raw vertex data (positions, texcoords, normals). You have to parse the file formats and extract the raw data, then use OpenGL to upload the data to the GPU.
For a TGA file, you basically just have to parse the file header to figure out what format the data is in (32-bpp RGBA, 8-bpp grayscale, etc.), strip out the footer, and the middle chunk of the file is the raw bitmap data. Sometimes TGA files are encoded with RLE, so you'd have to decode it before uploading. Here's a pretty good explanation of the format: [url]http://www.fileformat.info/format/tga/egff.htm[/url]
As for OBJ files, you parse it as plaintext. If you open up an obj file, you'll see that it's actually a very simple format. The word or letter before the first space is the description of what the value on that line represents. The most common ones you'll see are "v" - vertex position, "vt" - vertex texcoord, "vn" - vertex normal, and "f" - face indices. The values after that on the line are data. You have to store the positions, texcoords, and normals separately in sequential order, then create triangles with the values at the indices specified for each face ("f"). If you have texcoords and/or normals, face values will have slashes for each vertex of the triangle. That defines which texcoords and normals are used at each vertex in the order "position/texcoord/normal". The Wikipedia article on the format is pretty good: [url]http://en.wikipedia.org/wiki/Wavefront_.obj_file[/url]
There are libraries that handle parsing/loading file formats for textures and models, I would personally use them instead of trying to write my own:
[url]http://openil.sourceforge.net/[/url]
[url]http://assimp.sourceforge.net/[/url]
[QUOTE=CoolKingKaso;35390940]What is the general process for loading a tga file and an obj file in openGL? I've looked at coding, but I still don't get it yet.[/QUOTE]
[QUOTE=robmaister12;35391645]You don't "load" a tga or obj file in OpenGL
[...]
There are libraries that handle parsing/loading file formats for textures and models, I would personally use them instead of trying to write my own:
[url]http://openil.sourceforge.net/[/url]
[url]http://assimp.sourceforge.net/[/url][/QUOTE]
I can recommend DevIL (formerly OpenIL). I'm using it in my current OpenGL project and it works quite well. The documentation is kinda shitty - it doesn't fully describe some functions, others have the wrong C prototypes on their doc pages or have incorrect copy\pasted content but for the most part it's understandable and it's a damn sight easier than writing code to handle loading all those file formats yourself.
[editline]2nd April 2012[/editline]
If you want any tips on how to set it up\use it I can show you how I'm working with it in my project.
Anything I can improve on here?
Codes here: [url]http://pastebin.com/yXWnziq3[/url]
So I have to write an object Integral that takes a function pointer and two integration borders and returns the integral of that function yadda yadda. A few questions:
-why a pointer to a function instead of a function itself? I don't see the advantage. As far as I know, pointers are just like little cards that point to a book (function). Why not use the book (function) itself? For example a function "void g = a + b", why not use "g" to tell the compiler you're calling it? Why do you need a little card that points to g? (crappy analogy probably). My course says literally that the name of a function is also a pointer to that function, so that makes function pointers seem even more obsolete...
-so far I always had to add a member function setConstants that takes all of the object's arguments and checks if they are usable (e.g. no negative values and stuff like that), if they're good, it writes them to some private variables. What exactly are the advantages of this? Is it to ensure that nothing happens with the input values while the object does it's calculations?
Example of such a function:
[cpp]
ExampleClass::setConstants (double A, double B, etc... )
{
if (A > 0)
privateA=A;
else
cout << "No negative values allowed" << endl;
if (B ~ condition B)
privateB=B;
else
cout << "bla bla bla" << endl;
// AND SO ON
}
[/cpp]
-do I have to write the input function pointer also to a private function? Or a private function pointer? (whatever that may be). So far I have this in my class implementation:
[cpp]
#include "Integral.h"
Integral::Integral(double (*Fptr) (double), double A, double B)
{
setConstants(Fptr,A,B);
}
void Integral::setConstants(double (*Fptr) (double),double A,double B)
{
//Do nothing for now
}
[/cpp]
I had some trouble figuring out the syntax for a function pointer, and got it to work. I don't really know what I should do with *Fptr though (the input pointer to the function)
Should I write it to a private member function/variable/thingie?
[QUOTE=Number-41;35396654]Why do you need a little card that points to g? (crappy analogy probably)[/QUOTE]
Because you can't make Integral use a function directly. You need to tell it which function to use. You tell it that by writing down the function on a little card and giving it to Integral along with the other parameters.
Yeah a classmate just complained he couldn't calculate function values in his object directly, so I guess that's why it needs pointers. Still seems strange...
What method do people use to draw terrain using OpenGL? TriangleStrips?
Strips aren't to be used nowadays apparently?
so what does everyone use?
Sorry, you need to Log In to post a reply to this thread.