0

A follow up to: OpenGL4Net WM_PAINT does not exist?

I am still closely following: https://sourceforge.net/p/ogl4net/wiki/Tutorials

The program as it currently stands:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenGL4NET;

namespace pads2
{
    class Program : Form
    {
        private const int WM_PAINT = 15;
        RenderingContext rc;

        static void Main(string[] args)
        {
            Program program = new Program();
            program.Init();
            Application.Run(program);
        }

        // required for open GL
        void Init()
        {
            rc = RenderingContext.CreateContext(this);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        }

        void Render()
        {
            gl.Clear(GL.COLOR_BUFFER_BIT);

            // here is the right place to draw all your scene

            rc.SwapBuffers();
        }

        // change window size
        protected override void OnSizeChanged(EventArgs e)
        {
            gl.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
            // projection matrix may also need adjusting
        }

        // required for open GL
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_PAINT: Render(); break;
                default: base.WndProc(ref m); break;
            }
        }
    }
}

Q: Provided that I'm implementing the tutorial correctly, what can I do about the error System.BadImageFormatException on line program.Init();?

Additionally:

Additional information: Could not load file or assembly 'OpenGL4Net, Version=4.3.37.24, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

This could be due to the warning:

There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "OpenGL4Net", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

However according to:

How do I fix the Visual Studio compile error, "mismatch between processor architecture"?

This should not be an issue. There is only the option of (32 or 64) bit when downloading the OpenGL4Net DLL.

Given that Microsoft Intermediate Language is not the same as a processor, I tried running in release mode instead of debug mode, but it makes no difference.

Community
  • 1
  • 1
alan2here
  • 3,223
  • 6
  • 37
  • 62

1 Answers1

1

What build configuration do you use when compiling? And what version of OpenGL4Net did you download? The 32 or 64 bit version?

Try setting the build configuration to match the intended target cpu of the referenced assembly (so, either 32 or 64 bit, depending on the download of OpenGL4Net).

See C# compiling for 32/64 bit, or for any cpu? for a detailed explanation.

Community
  • 1
  • 1
Peter Bons
  • 26,826
  • 4
  • 50
  • 74
  • It was in "Debug" (having tried "Release") and "Any CPU". I've just created a specifically "64 bit CPU" in the build configuration and it worked! It seems that VS does not default to the CPU type that your CPU and OS are set to. | Discworld - Sam Vimes - "It was such a relief to be right, even though you knew you'd only got there by trying every possible way to be wrong." – alan2here Aug 08 '16 at 18:59