|
Compiling does not mean your code is right!
Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.
So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.
Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it. For example, if a program is intended to let the user enter a number and it doubles it and prints the answer, then if the input / output was like this:
Input Expected output Actual output
1 2 1
2 4 4
3 6 9
4 8 16 Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:
private int Double(int value)
{
return value * value;
}
Once you have an idea what might be going wrong, start using the debugger to find out why. Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff has given you some great advice on how to code, and debug.
Getting in the habit of setting break-points in Visual Studio, and then using F11 to single-step through the code, is a very important thing !
Here are a few suggestions, and code examples, to help you work out what's wrong with your code:
1. check that files, and directories, exist before you them.
2. when you want to automatically create a nested Directory structure:
destfile = System.IO.Path.Combine(targetpath + @"\f2\f3\f4", filename);
if (!Directory.Exists(destfile))
{
new FileInfo(destfile).Directory.Create();
} 3. Your code for 'Move works, but why would you copy a file, and then over-write it when you copy all the files in the same folder ?
Question: is it your intent, here, not to copy internal directories (recursively if nested) ?
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
BillWoodruff wrote: Question: is it your intent, here, not to copy internal directories (recursively if nested) ?
I do hope not!
string sourcepath=@"E:\\Anusha";
string targetpath=@"E:\\Anusha\\aaa";
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Given the confusion in the OP's code, it seemed reasonable to ask
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Your "Path.Combines" don't make sense.
Your file names are "full file names" and cannot be "combined".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hello everyone, I really need help about problem with loading of WaveFrontLoader.cs
I have tried to load obj but GameWindow doesn't show model why because it has nothing any errors.
I really want to have resolve WaveFront on my GameWindow
I will show code and file:
using OpenTK;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Tutorial_08.net.sourceskyboxer
{
public class WaveFrontLoader
{
private static List<Vector3> inPositions;
private static List<Vector2> inTexcoords;
private static List<Vector3> inNormals;
private static List<float> positions;
private static List<float> texcoords;
private static List<int> indices;
public static RawModel LoadObjModel(string filename, Loader loader)
{
inPositions = new List<Vector3>();
inTexcoords = new List<Vector2>();
inNormals = new List<Vector3>();
positions = new List<float>();
texcoords = new List<float>();
indices = new List<int>();
int nextIdx = 0;
using (var reader = new StreamReader("Contents/" + filename + ".obj", Encoding.UTF8))
{
string line = reader.ReadLine();
while (true)
{
string[] currentLine = line.Split(new[] { ' ' }, StringSplitOptions.None);
if (currentLine[0] == "v")
{
Vector3 pos = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3]));
inPositions.Add(pos);
if (currentLine[1] == "t")
{
Vector2 tex = new Vector2(float.Parse(currentLine[1]), float.Parse(currentLine[2]));
inTexcoords.Add(tex);
}
if (currentLine[1] == "n")
{
Vector3 nom = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3]));
inNormals.Add(nom);
}
}
if (currentLine[0] == "f")
{
Vector3 pos = inPositions[0];
positions.Add(pos.X);
positions.Add(pos.Y);
positions.Add(pos.Z);
Vector2 tc = inTexcoords[0];
texcoords.Add(tc.X);
texcoords.Add(tc.Y);
indices.Add(nextIdx);
++nextIdx;
}
reader.Close();
return loader.loadToVAO(positions.ToArray(), texcoords.ToArray(), indices.ToArray());
}
}
}
}
}
in Game.cs:
loader = new Loader();
shader = new StaticShader();
renderer = new Renderer(shader);
model = WaveFrontLoader.LoadObjModel("example", loader);
texturedModel = new TexturedModel(model, new ModelTexture(loader.loadTexture("example")));
entity = new Entity(texturedModel, new Vector3(0, 0, -40), 0, 0, 0, 1);
camera = new Camera();
Download myproblem.7z from mega.nz
How do I resolve if wavefront obj displays in GameWindow Thank you for checking and resolving.
Please promise me! I want listen how do I get working wavefrontloader.cs should parse to obj file. Thank you!
I am very broken since Sunday to today I can not resolve it cause WavefrontLoader can know Obj but doesn't show in GameWindow. How do I get successful loading obj. But it is really porting from LwjGL into C# OpenTK. Thanks for help!
|
|
|
|
|
|
Why do you use old OpenTK?
STOP PLEASE CHECK CAREFUL BECAUSE VERY LATEST VERSION of OPENTK from Github and MyGet Server That is not old.
For Neo Kabuto is very same to CrazyCore ( like it looks like you have played Valve Hammer Editor with unlimited edges with very large face like broken object made biggest faces like it seems "error-faces" )
That is same I have played Neo Kabuto's last tutorial 8 Step 2 = 2 planes and 1 television ( it happens unlimited face ( = error-face ) for latest OpenTK cause object looks like Half-Life-style binary structure ( bsp 30 version and for object is broken with error-faces.
If you don't know about error-faces?
What is an error-face?
Example like CrazyCore in game happens
Picture 1
Picture 2
That is really bad.
But I found SharpGL's ObjFileLoader.cs
It is really very old for OpenTK.
How do I understand for structure of wavefront file ( obj )
Please explain current for very latest version with while loop-like compilication!
That is very hard because latest version = unknown
old version = same version.
If it happens with Blender'S wavefront is buggy or stable. I am not sure Please check who has exported successful with 3D Max or 3D GameStudio-ModelEditor or Milkshape or Softimage XSI and other
What is wavefront version for now? If it is same old or newest version?
That is reason.
I need know how does latest OpenTK read Wavefront file?
If you have tried wavefront in my example ( Tutorial_08 ) Did you try obj in GameWindow to show - If it is still not visible than it means buggy or I write wrong while-loop?
Thank you for explanation!
Thank you!
|
|
|
|
|
Less coffee.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes But I got working obj loader = no problem but faces of obj are really painfully
Look out picture: [^]
How do I fix it?
My code was very close resolved but faces are not okay now. :/
WavefrontLoader.cs
using OpenTK;
using System;
using System.Collections.Generic;
using System.IO;
namespace Tutorial_08.net.sourceskyboxer
{
public class WaveFrontLoader
{
private static List<Vector3> vertices;
private static List<Vector2> textures;
private static List<Vector3> normals;
private static List<int> indices;
private static float[] verticesArray;
private static float[] normalsArray;
private static float[] texturesArray;
private static int[] indicesArray;
public static int vertexPointer;
public static RawModel LoadObjModel(string filename, Loader loader)
{
vertices = new List<Vector3>();
textures = new List<Vector2>();
normals = new List<Vector3>();
indices = new List<int>();
using (var reader = new StreamReader(new FileStream("Contents/" + filename + ".obj", FileMode.Open, FileAccess.Read)))
{
string line;
try
{
while (true)
{
line = reader.ReadLine();
string[] currentLine = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (currentLine[0] == "v")
{
Vector3 vertex = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3]));
vertices.Add(vertex);
} else
if (currentLine[0] == "vt")
{
Vector2 texture = new Vector2(float.Parse(currentLine[1]), float.Parse(currentLine[2]));
textures.Add(texture);
}else
if (currentLine[0] == "vn")
{
Vector3 normal = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3]));
normals.Add(normal);
}
else
if (currentLine[0] == "f")
{
texturesArray = new float[vertices.Count * 2];
normalsArray = new float[vertices.Count * 3];
break;
}
}
while (line != null)
{
if (!line.StartsWith("f"))
{
line = reader.ReadLine();
continue;
}
string[] currentLine = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string[] vertex_1 = currentLine[1].Split(char.Parse("/"));
string[] vertex_2 = currentLine[2].Split(char.Parse("/"));
string[] vertex_3 = currentLine[3].Split(char.Parse("/"));
ProcessVertex(vertex_1, indices, textures, normals, texturesArray, normalsArray);
ProcessVertex(vertex_2, indices, textures, normals, texturesArray, normalsArray);
ProcessVertex(vertex_3, indices, textures, normals, texturesArray, normalsArray);
line = reader.ReadLine();
}
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
verticesArray = new float[vertices.Count * 3];
indicesArray = new int[indices.Count];
vertexPointer = 0;
foreach (Vector3 vertex in vertices)
{
verticesArray[vertexPointer++] = vertex.X;
verticesArray[vertexPointer++] = vertex.Y;
verticesArray[vertexPointer++] = vertex.Z;
}
for (int i = 0; i < indices.Count; i++)
{
indicesArray[i] = indices[i];
}
reader.Close();
}
return loader.loadToVAO(verticesArray, texturesArray, indicesArray);
}
private static void ProcessVertex(string[] vertexData, List<int> indices,
List<Vector2> textures, List<Vector3> normals, float[] texturesArray, float[] normalsArray)
{
int currentVertexPointer = int.Parse(vertexData[0]) - 1;
indices.Add(currentVertexPointer);
Vector2 currentTex = textures[int.Parse(vertexData[1]) - 1];
texturesArray[currentVertexPointer * 2] = currentTex.X;
texturesArray[currentVertexPointer * 2 + 1] = 1 - currentTex.Y;
Vector3 currentNorm = normals[int.Parse(vertexData[2]) - 1];
normalsArray[currentVertexPointer * 3] = currentNorm.X;
normalsArray[currentVertexPointer * 3 + 1] = currentNorm.Y;
normalsArray[currentVertexPointer * 3 + 2] = currentNorm.Z;
}
}
}
And Renderer.cs ( I have fixed cause it looks sometimes wrong GL:DrawElement() or GL.DrawArrays()
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using Tutorial_08.net.sourceskyboxer.entities;
namespace Tutorial_08.net.sourceskyboxer
{
public class Renderer
{
private const float NEAR_PLANE = 0.1f;
private const float FAR_PLANE = 1000000;
public Renderer(StaticShader shader)
{
CreateProjectionMatrix();
shader.start();
shader.LoadProjectionMatrix(projectionMatrix);
shader.stop();
}
private Matrix4 projectionMatrix;
public virtual void prepare()
{
GL.ClearColor(Color4.Orange);
GL.Enable(EnableCap.DepthTest);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
}
public virtual void render(Entity entity, StaticShader shader)
{
TexturedModel model = entity.Model;
RawModel rawModel = model.RawModel;
GL.BindVertexArray(rawModel.VaoID);
GL.EnableVertexAttribArray(0);
GL.EnableVertexAttribArray(1);
Matrix4 transformationMatrix = Maths.CreateTransformationMatrix(entity.Position.X, entity.Position.Y, entity.Position.Z, entity.RotX, entity.RotY, entity.RotZ, entity.Scale);
shader.LoadTransformationMatrix(transformationMatrix);
GL.ActiveTexture(TextureUnit.Texture0);
GL.BindTexture(TextureTarget.Texture2D, model.ModelTexture.TextureID);
GL.DrawElements(BeginMode.Triangles, rawModel.VertexCount, DrawElementsType.UnsignedShort, 0);
GL.DisableVertexAttribArray(1);
GL.DisableVertexAttribArray(0);
GL.BindVertexArray(0);
}
private void CreateProjectionMatrix()
{
float aspectRadio = Game.GameWIdth / Game.GameHeight;
projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRadio, NEAR_PLANE, FAR_PLANE);
}
}
}
And I have fixed texture cause CLampEdges makes black
I remove both GL.TexParameter
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using OpenTK.Graphics.OpenGL4;
namespace Tutorial_08.net.sourceskyboxer
{
public class Loader
{
private IList<int> vaos = new List<int>();
private IList<int> vbos = new List<int>();
private IList<int> textures = new List<int>();
public virtual RawModel loadToVAO(float[] positions, float[] textureCoords, int[] indices)
{
int vaoID = createVAO();
bindIndicesBuffer(indices);
storeDataInAttributeList(0, 3, positions);
storeDataInAttributeList(1, 2, textureCoords);
unbindVAO();
return new RawModel(vaoID, indices.Length);
}
public int loadTexture(string textureName)
{
if(!File.Exists("Contents/"+textureName+".png"))
{
throw new FileNotFoundException("Error: texture files doesn't exist path: "+textureName+".png");
}
int textureID = GL.GenTexture();
textures.Add(textureID);
GL.BindTexture(TextureTarget.Texture2D, textureID);
Bitmap bmp = new Bitmap("Contents/" + textureName + ".png");
System.Drawing.Imaging.BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, data.Scan0);
bmp.UnlockBits(data);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
return textureID;
}
public virtual void cleanUp()
{
foreach (int vao in vaos)
{
GL.DeleteVertexArray(vao);
}
foreach (int vbo in vbos)
{
GL.DeleteBuffer(vbo);
}
foreach(int texture in textures)
{
GL.DeleteTexture(texture);
}
}
private int createVAO()
{
int vaoID = GL.GenVertexArray();
vaos.Add(vaoID);
GL.BindVertexArray(vaoID);
return vaoID;
}
private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data)
{
int vboID = GL.GenBuffer();
vbos.Add(vboID);
GL.BindBuffer(BufferTarget.ArrayBuffer, vboID);
GL.BufferData(BufferTarget.ArrayBuffer, (data.Length * sizeof(float)), data, BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(attributeNumber, coordinateSize, VertexAttribPointerType.Float, false, 0, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
}
private void bindIndicesBuffer(int[] indices)
{
int vboId = GL.GenBuffer();
vbos.Add(vboId);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, vboId);
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(int)), indices, BufferUsageHint.StaticDraw);
}
private void unbindVAO()
{
GL.BindVertexArray(0);
}
}
}
Do you mean I should replace StreamReader() with path of bitmap/texture? Or I should fix faces of WavefrontLoader.cs?
|
|
|
|
|
Why potential spam? That is not potential spam just I show 2 important pictures like CrazyCore's wavefront happens
|
|
|
|
|
Wasn't me.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
If you are talking about your message going to the approval process, that's what happens when you are new and you post messages with links in. The automatic spam detectors kick in and you have to wait for a manual approved to approve your article. We get a lot of spam so this is necessary.
This space for rent
|
|
|
|
|
Wow spammings only spams because you are really scared. Please check me! I am not spammer just I am serious and tell that. If you don't believe than I will leave CodeProject if you say about spam, spam , spam? Hello I am not Facebook user. I am very hostile to Facebook. Why do you always talk about spams - please check users are trusted people and they are not spambots just real human.
Thank you!
|
|
|
|
|
Calm down and get a grip. I didn't accuse you of spam. I said that the automatic spam detectors would have flagged your message for investigation because it contained links and you don't have anywhere near enough reputation on the site to he automatically whitelisted. We get dozens, sometimes hundreds, of spam messages a day and if they weren't flagged they would make the forums unusable. Now, if you want to continue throwing a strop, please feel free. Alternatively you could calm down and realise that your message was let through so the person who reviewed it didn't consider it as spam.
This space for rent
|
|
|
|
|
hi
i have two forms
form1 run with button click and doing a foreach loop
i want to every time need to show form2 in the foreach loop, then pause button click event until i have to select an item from form2.listbox then continue button click event
please help me what should i do?
thanks you dear friends
|
|
|
|
|
Simply disable the control before you start your loop. Or disconnect the event when going into the loop, and reconnect when done. Or in the event, check whether you're looping and exit.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Simple:
Form2 f2 = new Form2();
f2.ShowDialog(); the Form1 code will cease working until Form2 is closed, and then continue from the next line.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If you create a new instance of Form2 inside the 'for loop on Form1 ... where the user makes some choice through direct action ... unless you somehow pass the result of the user action back to Form1 ... then there is no point showing Form2.
I suggest:
1. create one instance of Form2 in Form1
2. create a public delegate (use 'Action) in Form2 that is invoked in the ListBox SelectedValueChanged event handler.
3. in Form1 insert your code for the Action into the instance of Form2.
4. in the for loop on Form1 show Form2 using ShowDialog
Form1
using System;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Form2 f2 = new Form2();
string listBoxChoice;
private void Form1_Load(object sender, EventArgs e)
{
f2.SendListBoxChoice += SendListBoxChoice;
}
private void SendListBoxChoice(string choice)
{
listBoxChoice = choice;
}
private void testButton_Click(object sender, EventArgs e)
{
for (int i = 0; i < 2; i++)
{
listBoxChoice = "";
f2.ShowDialog(this);
if (listBoxChoice != "")
{
switch (listBoxChoice)
{
case "1":
break;
}
}
}
}
}
} Form2
using System;
using System.Windows.Forms;
namespace Test
{
public partial class Form2 : Form
{
public Action<string> SendListBoxChoice;
public Form2()
{
InitializeComponent();
}
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (SendListBoxChoice != null)
{
SendListBoxChoice(listBox1.SelectedItem.ToString());
}
}
}
}
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
i designed real estate management system in c#.net and sql server and then have faced problem coding in part of managimg chegues the idea is that the system must send warning message when the contract going to end for examlpe.
in a litle words: i want help how to write code produce warning message before specific time in in c#.net and sql server.
thanks i hope you help me,please i am my final project
|
|
|
|
|
We can't be specific; we have no idea how your system works, how it's written, or even where you get "contract" information from.
But there are three basic ways:
1) A separate application which is run by the system at scheduled intervals which checks the times and reports.
2) A Timer in your application which does the same thing - runs and the contracts are checked each time the Tick handler is called.
3) A Thread in your application which does the same thing: sleeps for a period, then checks the contract times.
Which is best for your application? No idea!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ahmedoze wrote: i hope you help me,please i am my final project I never did one of those.
So, assuming you have a list of stuff with dates in SQL Server. When the program runs, you fetch all the mail-adresses that have the date "today". Check with an "if" whether or not to send a mail. What part of that are you stuck on?
For bonus points; if you run the program again, or if it crashes half-way, it may send some mails twice. To be correct, you'd need to remember whom you sent a mail and exclude them when fetching todays stuff.
How much time until your deadline?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: How much time until your deadline? He won't know until he can get his application to post a warning message.
|
|
|
|
|
If this is your final project, you should know by now how to create a specification. You only have the highest level of requirement there. When you say that you want the system to send a warning message, for instance, how do you want that warning to be delivered? Are you sending it to a user logged into your system? Are you sending it to clients via email/text? You need to spend more time working out what your requirements are.
If, for instance, you wanted just to send this to a client via email, then you know that there is a possibility that the client isn't going to be logged into your system at an appropriate point. This tells you that you want to write something that can send updates to people as an unattended operation - in other words, you're probably going to want to write a service. You also need some way to identify that you have already sent a notification, so you probably want to have some attribute in the database, against the client, to identify that the message has been sent.
We aren't going to write your code for you, but we will give you ideas on how to start coming up with your own solution.
This space for rent
|
|
|
|
|
First fall Your application will be used by specific users, IF Yes then, when those users login to your application based on your logic you can write the code and display warning message on the screen.
OR
IF Users not login into your application, and you need to send an emails to your client or customers then you need to write a Service, based on that service you can send an emails/warning messages.
If you can give some more details then it will be easy to figure out the way....
|
|
|
|
|