小编Neo*_*mex的帖子

C ++绘图像素问题


如何制作窗口,或更像是剪切区域,我可以在其中绘制像素?它可能使用WinApi,但是我不希望我的项目看起来像winapi,所以它将

int main(){}
Run Code Online (Sandbox Code Playgroud)

代替

int WINAPI WinMain(HINSTANCE ...
Run Code Online (Sandbox Code Playgroud)

我找到了一个示例,可以在控制台窗口中绘制

int main()
{
    COLORREF color = RGB(255,0,0); // COLORREF to hold the color info

    SetConsoleTitle("Pixel In Console?"); // Set text of the console so you can find the window

    HWND hwnd = FindWindow(NULL, "Pixel In Console?"); // Get the HWND
    HDC hdc = GetDC(hwnd); // Get the DC from that HWND

    for( int i = 0 ; i < 50 ; i++ )
    {
    SetPixel(hdc, 5+i, 12, color); // SetPixel(HDC hdc, …
Run Code Online (Sandbox Code Playgroud)

c++ winapi pixel

1
推荐指数
1
解决办法
1万
查看次数

随机数字不起作用

可能的重复:
为什么我的随机数生成器在C#中不是随机的?
随机数发生器不按我计划的方式工作(C#)

您好,
我使用此函数(在类中)随机化数字:

private int RandomNumber(int min, int max)
{
    Random random = new Random();
    return random.Next(min, max);
}

public void Init()
{
    x = RandomNumber(0,500);
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我稍后调用多个对象来执行此操作:

Obj[] obj = new Obj[64];
for( int i = 0 ; i < 64 ; i++ )
{
    obj[i] = new Obj();
}
...
for( int i = 0 ; i < 64 ; i++ )
{
    obj[i].Init();
}
Run Code Online (Sandbox Code Playgroud)

那么每个对象都有完全相同的'x'值.

这有什么不对?

c#

1
推荐指数
1
解决办法
727
查看次数

"此模型不包含SkinningData标记." 例外

我一直在使用wikibooks的教程,但我坚持模型渲染.(http://en.wikibooks.org/wiki/Creating_a_Simple_3D_Game_with_XNA/Rendering_Your_Model)当我尝试编译时,我得到了这个异常:"这个模型不包含SkinningData标记."

我的意思是,该模型未正确导出,但在使用其网站模型后无法正常工作.

我会感谢任何帮助.

xna blender

1
推荐指数
1
解决办法
2135
查看次数

在完成所有绘图代码后,是否需要重复glOrtho调用?

我用OpenGL创建2D游戏.每次我移动我的对象时,我都要调用glLoadIdentity,因为否则所有对象都会移动,但glLoadIdentity也会重置glOrtho调用,所以基本上我以这样的结尾:

#include <GL/glfw.h>

int main()
{
glfwInit();

glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE );
glfwOpenWindowHint( GLFW_FSAA_SAMPLES, 8 );
glfwOpenWindow( 800, 600, 0, 0, 255, 0, 32, 0, GLFW_WINDOW );

glfwSetWindowTitle( "title" );

glfwSwapInterval( 1 ); // also known as 'vsync'

glfwEnable( GLFW_KEY_REPEAT );
//glfwDisable( GLFW_MOUSE_CURSOR );

glOrtho(0.0, 1024, 768, 0, -1.0, 1.0); 
glMatrixMode( GL_MODELVIEW );

while( !glfwGetKey( GLFW_KEY_ESC ) )
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glLoadIdentity();
    glOrtho(0.0, 1024, 768, 0, -1.0, 1.0); 

    glTranslatef( 100, 0, 0 …
Run Code Online (Sandbox Code Playgroud)

c c++ opengl

1
推荐指数
1
解决办法
1303
查看次数

将委托从一个类传递给另一个类

我有两个班,第一个:

    public class A
    {
        public delegate void Function();

        public string name;
        public Function function;

        public A(string name, Function function)
        {
            this.name = name;
            this.function = function;
        }
    }
Run Code Online (Sandbox Code Playgroud)

第二个:

    public class B
    {
        public delegate void Function();
        List<A> ListA;

        // somewhere in function
        void F()
        {
            ListA[i].function();
        }
        // ---

        public void AddA(string name, Function function)
        {
            ListA.Add(new A(name, function)); // error here
        }
    }
Run Code Online (Sandbox Code Playgroud)

它抛出这些错误:

Error   2   Argument 2: cannot convert from 'App.B.Function' to 'App.A.Function'
Error   1   The …
Run Code Online (Sandbox Code Playgroud)

c# delegates

1
推荐指数
1
解决办法
148
查看次数

#undef main没有结果

我正在使用MVisualC++ 2010,当我尝试取消定义"main"时,没有结果,控制台像往常一样启动.我期待一些丢失的入口点错误或其他什么.这是为什么?

#undef main
int main()
{
}
Run Code Online (Sandbox Code Playgroud)

c++ program-entry-point undef visual-studio-2010

0
推荐指数
1
解决办法
949
查看次数

超出数组范围的值

我正在迭代数组,有时我必须检查超出边界的值.当然它会抛出异常,但我不想完全停止它之后的应用程序,只是跳过这个代码元素.

这样安全,不会导致内存泄漏吗?

try
{
    if (arrayName[i - 1, j].DoSomething())
         something++;
}
catch
{ // empty for purpose
}
Run Code Online (Sandbox Code Playgroud)

c# arrays exception-handling

0
推荐指数
1
解决办法
4241
查看次数

如何使用原始重启功能

我正在尝试制作地形网格,现在得到这样的东西:

    GL.PushMatrix();
    GL.Begin(BeginMode.TriangleStrip);

    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 6; j++)
        {
            GL.Vertex2(0 + 50 * j, 0 + 50 * i);
            GL.Vertex2(0 + 50 * j, 0 + 50 + 50 * i);
        }

    }

    GL.End();
    GL.PopMatrix();
Run Code Online (Sandbox Code Playgroud)

但它看起来不像是假设,它应该如何正确完成?

图片http://img821.imageshack.us/img821/5387/otkl.jpg

opengl

-1
推荐指数
1
解决办法
2441
查看次数