Azenris

Members
  • Content count

    23
  • Joined

  • Last visited

Community Reputation

139 Neutral

About Azenris

  • Rank
    Member
  1. Writing to a file

    The while(1); just creates an infinite loop, essentially halting the program displaying the last error message. The handle is checked before using strcpy (however it was done in the CreateHandle function I didn't give you the source on in the post). I'll try the std::ios::binary as a second parameter, ty for the suggestion. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] II thought the (end + 1) would return the position past the . (i.e. the extension) Ill double check it though. EDIT: Not treating the file as binary was the problem, THANKS!
  2. Hi, i have this function where I must be misunderstanding something because it is not as expected and I cannot figure out whats going on. Hoping for some help [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] [code] std::string CreateTempConvertedGfx(const std::string & name, const std::string & filename) { std::string handle = CreateHandle(name); std::string tempFileName = "temps/" + handle + ".tmp"; TargaImage image; if (!image.load(filename)) { std::cout << "ERROR: Could not load targa image: " << filename << std::endl; while(1); } int frames = 1; int frameDelay = 10; int frameWidth = 16; int frameHeight = 16; ReadGDFFile(filename, frames, frameDelay, frameWidth, frameHeight); frames = image.getWidth() / frameWidth; GRAPHIC_DATA gfxData; strcpy(gfxData.m_handle, handle.c_str()); gfxData.m_frames = frames; gfxData.m_frameDelay = frameDelay; gfxData.m_frameWidth = frameWidth; gfxData.m_frameHeight = frameHeight; gfxData.m_textureWidth = image.getWidth(); gfxData.m_textureHeight = image.getHeight(); gfxData.m_textureSize = image.getSize(); std::ofstream dstFile(tempFileName); if (dstFile.is_open() == false) { std::cout << "ERROR: Could not open dst: " << tempFileName << std::endl; while(1); } long startp = dstFile.tellp(); dstFile.write((char *)&gfxData, sizeof(GRAPHIC_DATA)); // temp - THIS IS WRITING 61 BYTES WHEN GRAPHIC_DATA is 60 ?! // temp // these should be equal, and they are for Potion, the one with a gdf file // if you remove the gdf file it stops working and any you add one too // start to work // why does having a gdf file making it work and not having one break it long tellpp = dstFile.tellp(); if (tellpp != sizeof(GRAPHIC_DATA)) { std::cout << "ERROR: " << tempFileName << " [" << tellpp << " / " << sizeof(GRAPHIC_DATA) << "] : " << startp << std::endl; while(1); } // end temp dstFile.write((char *)image.getImageData(), image.getSize()); dstFile.close(); return tempFileName; } [/code] The problem is, the line dstFile.write((char *)&gfxData, sizeof(GRAPHIC_DATA)); After calling this I check the the position with tellp and it ends up 1 position ahead of where it should be (i think). The weird thing is, this write only goes 1 position past IF I have a .gdf file (just a basic file with some info). The output ill get is ERROR: temps/Attribute_Damage.tmp [61/60] : 0 And this error is for all files where ReadGDFFile doesnt open anything. Here is the source to that incase [code] void ReadGDFFile(const std::string & filename, int & frames, int & frameDelay, int & frameWidth, int & frameHeight) { std::string gdfFilename = filename; size_t end = gdfFilename.find_last_of("."); if (end == std::string::npos) { std::cout << "ERROR: Invalid file name" << std::endl; while(1); } gdfFilename = gdfFilename.substr(0, end + 1) + "gdf"; std::ifstream gdfFile(gdfFilename); if (gdfFile.is_open()) { std::string option; while (gdfFile.eof() == false) { gdfFile >> option; if (option == "frameDelay") { gdfFile >> frameDelay; } else if (option == "frameWidth") { gdfFile >> frameWidth; } else if (option == "frameHeight") { gdfFile >> frameHeight; } else { std::cout << "Unknown GDF attribute name: " << option; while(1); } } gdfFile.close(); } } [/code] [code] const int MAX_GFX_NAME = 32; #pragma pack(push, 1) struct GRAPHIC_DATA { char m_handle[MAX_GFX_NAME]; int m_frames; int m_frameDelay; int m_frameWidth; int m_frameHeight; int m_textureWidth; int m_textureHeight; int m_textureSize; }; #pragma pack(pop) [/code] The thing is Im not sure how anything changes how much data is written. sizeof(GRAPHIC_DATA) should always be the same. Please ask if you need more info. I have attached the source. To test, compile, then drag and drop the "files" folder onto the exe in the debug folder. Thanks for any help.
  3. Thank you, the naming issue was the problem. TY for all the help.
  4. This shader is the only one being used yea, its nothing more than a demo to learn about GLSL... what a road block at step one [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] I'm curious is everyone else getting the flashing triangle if they run the app? I tried to change to shaders abit. First I changed the frag shader [code] in vec4 in_colour; out vec4 out_colour; void main(void) { out_colour = in_colour; } [/code] to [code] in vec4 in_colour; out vec4 out_colour; void main(void) { out_colour = vec4(1.0, 1.0, 0.0, 1.0); } [/code] The output was then a yellow triangle (no flickering in the colour) I then tried a second experiment with changing the vertex shader. (after i changed the fragment shader back) from [code] uniform mat4 projection_matrix; uniform mat4 modelview_matrix; in vec3 in_vertex; in vec3 in_colour; out vec4 out_colour; void main(void) { gl_Position = projection_matrix * modelview_matrix * vec4(in_vertex, 1.0); out_colour = vec4(in_colour, 1.0); } [/code] to [code] uniform mat4 projection_matrix; uniform mat4 modelview_matrix; in vec3 in_vertex; in vec3 in_colour; out vec4 out_colour; void main(void) { gl_Position = projection_matrix * modelview_matrix * vec4(in_vertex, 1.0); out_colour = vec4(1.0, 1.0, 0.0, 1.0); } [/code] This resulted in the original colour flickering. Does this mean anything to you? Maybe I wrote the fragment shader wrong? Does it look right to you? Its like the fragment shader is changing the colour even though all I do is take the input for the output.
  5. Do you mean to modify my render to this [code] void CApplication::Render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glGetFloatv(GL_PROJECTION_MATRIX, projMatrix); glGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); shader.sendUniform("projection_matrix", projMatrix); shader.sendUniform("modelview_matrix", modelMatrix); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[COLOUR_BUFFER]); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0); } [/code] I added the glBindBuffer/glVertexAttribPointer each frame. Doesnt seem to change anything. I checked sizeof(CColour), it is 12 bytes. Here is what the class looks like [code] #ifndef HG_GEOMETRY_H #define HG_GEOMETRY_H #include "mgl.h" #pragma pack(push, 1) class CVertex { public: CVertex(GLfloat _x, GLfloat _y, GLfloat _z) : x(_x) , y(_y) , z(_z) { } GLfloat x; GLfloat y; GLfloat z; }; class CColour { public: CColour(GLfloat _r, GLfloat _g, GLfloat _b) : r(_r) , g(_g) , b(_b) { } GLfloat r; GLfloat g; GLfloat b; }; class CIndex { public: CIndex(GLuint _index) : index(_index) { } GLuint index; }; #pragma pack(pop) #endif [/code]
  6. I noticed an error in the code i uploaded [code] shader.bindAttrib(0, "in vertex"); shader.bindAttrib(1, "in_colour"); [/code] It uses an incorrect name. However this causes no issues I think as the location 0 is always for verticies. I changed it anyway and the problem still persists. I also added [code] if (glGetAttribLocation(shader.m_programID, "in_vertex") != 0) LOG->Send("Something gone wrong #1"); if (glGetAttribLocation(shader.m_programID, "in_colour") != 1) LOG->Send("Something gone wrong #2"); [/code] just to make sure its bound ok. Still not sure why the colour is flickering. I tried to google and couldnt find anything on it.
  7. [quote name='Azenris' timestamp='1339094147' post='4947124'] I Have tried previous suggestions to the location where I bind but has no effect. Any help appreciated. Thanks ! [/quote] I tried, It didnt seem to have any effect on my code, Ill put it as you mentioned however my problem persists.
  8. I am still having problems. I changed my code so the fragment shader was setting the colour to yellow. This worked fine and I got a yellow triangle. However when I changed back to passing the colour variable in to the shader, I got this bug where the triangle would flicker between colours rapidly. I have included an attachment of my program. I have cut it down to the important stuff. After compiling run the .exe in "temptest.zip\temptest\Debug" this is where the shsders are located. Here is some of the code incase you dont want to download my program. App [code] #include "application.h" #include "log.h" CApplication::CApplication(void) : m_appName("TESTING GLSL") , shader(GLSLProgram("vert_shader.vert", "frag_shader.frag")) { } CApplication::~CApplication(void) { } bool CApplication::Init(void) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); if (!shader.initialize()) LOG->Send("Failed to compile shader"); shader.bindAttrib(0, "in vertex"); shader.bindAttrib(1, "in_colour"); shader.linkProgram(); shader.bindShader(); if (!glGenBuffers || !glBindBuffer || !glBufferData) LOG->Send("VBOs not supported by your graphics card"); // VERTEX glGenBuffers(LAST_BUFFER, m_vbos); vertices.push_back(CVertex(-1.0f, -0.5f, -4.0f)); vertices.push_back(CVertex(1.0f, -0.5f, -4.0f)); vertices.push_back(CVertex(0.0f, 0.5f, -4.0f)); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(CVertex), &vertices[0], GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); // COLOUR colors.push_back(CColour(1.0f, 0.0f, 1.0f)); colors.push_back(CColour(1.0f, 0.0f, 1.0f)); colors.push_back(CColour(1.0f, 0.0f, 1.0f)); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[COLOUR_BUFFER]); glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(CColour), &colors[0], GL_STATIC_DRAW); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); // INDEX indices.push_back(CIndex(0)); indices.push_back(CIndex(1)); indices.push_back(CIndex(2)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(CIndex), &indices[0], GL_STATIC_DRAW); return true; } void CApplication::Update(float elapsed) { } void CApplication::Render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glGetFloatv(GL_PROJECTION_MATRIX, projMatrix); glGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); shader.sendUniform("projection_matrix", projMatrix); shader.sendUniform("modelview_matrix", modelMatrix); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0); } void CApplication::Release(void) { } void CApplication::OnResize(int width, int height) { if (height == 0) height = 1; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(52.0f, float(width) / float(height), 1.0f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } std::string CApplication::GetAppName(void) const { return m_appName; } [/code] Vert shader [code] #version 130 uniform mat4 projection_matrix; uniform mat4 modelview_matrix; layout(location = 0) in vec3 in_vertex; layout(location = 1) in vec3 in_colour; out vec4 out_colour; void main(void) { gl_Position = projection_matrix * modelview_matrix * vec4(in_vertex, 1.0); out_colour = vec4(in_colour, 1.0); } [/code] Frag shader [code] #version 130 in vec4 in_colour; out vec4 out_colour; void main(void) { out_colour = in_colour; } [/code] I Have tried previous suggestions to the location where I bind but has no effect. Any help appreciated. Thanks !
  9. bah [code] glGetFloatv(GL_PROJECTION, projMatrix); glGetFloatv(GL_MODELVIEW, modelMatrix); [/code] should have been [code] glGetFloatv(GL_PROJECTION_MATRIX, projMatrix); glGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); [/code] Atleast that works now, Gonna try moving away from te builtin matrix stack now tho. Ty for the help.
  10. Im just starting out with this trying to get a triangle to show coloured. It currently only shows as white though. Probably something simple I'm overlooking, but I cant seem to see it. [code] CApplication::CApplication(void) : m_appName("<Name> - <Build Version>") , shader(GLSLProgram("basic_tex.vert", "basic_tex.frag")) { } [/code] [code] bool CApplication::Init(void) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); shader.bindAttrib(0, "a_Vertex"); shader.bindAttrib(1, "a_Color"); shader.linkProgram(); shader.bindShader(); if (!glGenBuffers || !glBindBuffer || !glBufferData) LOG->Send("VBOs not supported by your graphics card"); // VERTICIES glGenBuffers(LAST_BUFFER, m_vbos); vertices.push_back(CVertex(-1.0f, -0.5f, -4.0f)); vertices.push_back(CVertex(1.0f, -0.5f, -4.0f)); vertices.push_back(CVertex(0.0f, 0.5f, -4.0f)); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(CVertex), &vertices[0], GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); // INDEX LIST indices.push_back(CIndex(0)); indices.push_back(CIndex(1)); indices.push_back(CIndex(2)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(CIndex), &indices[0], GL_STATIC_DRAW); // COLOURS colorBuffer.push_back(CColour(1.0f, 0.0f, 0.0f)); colorBuffer.push_back(CColour(1.0f, 0.0f, 0.0f)); colorBuffer.push_back(CColour(1.0f, 0.0f, 0.0f)); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[COLOUR_BUFFER]); glBufferData(GL_ARRAY_BUFFER, colorBuffer.size() * sizeof(CColour), &colorBuffer[0], GL_STATIC_DRAW); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]); return true; } [/code] [code] void CApplication::Render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glGetFloatv(GL_PROJECTION, projMatrix); glGetFloatv(GL_MODELVIEW, modelMatrix); shader.sendUniform("modelview_matrix", modelMatrix); shader.sendUniform("projection_matrix", projMatrix); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0); } [/code] [code] void CApplication::OnResize(int width, int height) { if (width == 0) height = 1; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(52.0f, float(width) / float(height), 1.0f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } [/code] vertshader [code] uniform mat4 projection_matrix; uniform mat4 modelview_matrix; layout(location = 0) in vec3 a_Vertex; layout(location = 1) in vec3 a_Color; out vec4 color; void main(void) { gl_Position = projection_matrix * modelview_matrix * vec4(a_Vertex, 1.0); color = vec4(a_Color, 1.0); } [/code] frag shader [code] in vec4 color; out vec4 outColor; void main(void) { outColor = color; } [/code] As mentioned my problem is a white triangle is shown on the screen. Currently I wanted it to show red, and eventually be able to specify each vertex a different colour. Hope I managed to post across relevant information and placed it in the correct place Is there anything that sticks out as wrong? BTW if you need more information just ask and I'l put it up Thankyou for any help !
  11. Getting Obj1 to face Obj2

    Thanks, I'll try it out.
  12. Getting Obj1 to face Obj2

    Hi, I was wondering how I calculate this angle shown in the examples below I have the position of both objects, 0 starts east. X incs right Y incs down
  13. Forward Delcarations

    never actually made my own namespace, dont know much about it. guess I could take alook at them, same I cant do it directly :( TY
  14. Forward Delcarations

    Hi, i know how to declare a basic class/struct but is it possible to somehow have what I have below. // =============================================================================== // FORWARD DECLARATIONS: class CScreenManager::MOBILE; // =============================================================================== // FUNCTIONS: bool test_dustbin_func_eo(CScreenManager::MOBILE *pMobile); bool test_dustbin_func_so(CScreenManager::MOBILE *pMobile); Is it possible to forward declare the CScreenManager::MOBILE struct? Im not sure how I would go about it, or whether I need to redesign it. Id rather not include the entire screen header into this header. TY for any help
  15. BMP, writing to a struct

    Yea that was the problem, thanks guys, its solved now.