如何与opengl并行运行程序

钟表

我想运行opengl,我也想执行我的c代码... xD创建窗口后,没有代码执行...这正常吗?还是我只需要更好地了解opengl:D

也许我需要将我的C代码放在一些opengl循环xD中,例如放入空闲函数^^

//============================================================================
// Name        : cpu_Emulation_19-10-13.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
//https://fms.komkon.org/EMUL8/HOWTO.html

// todo: iam programming the dissambler which just checks my given in commands.. 1927 - 31.10.2019
#include <iostream>
#include <stdint.h>
#include "C8Klasse.h"
#include "Cartridge.h"
#include <stdio.h>
#include <GL/glut.h>
#include <intrin.h> // damit kann man zyklen auslesen...https://stackoverflow.com/questions/13772567/how-to-get-the-cpu-cycle-count-in-x86-64-from-c
using namespace std;
//  Windows
//#ifdef _WIN32

// what does this whole thing: it ist a Chip8 Interpreter
unsigned short int memory[1000]; // annahem
void initMemory() {
    memory[0] = 0;
    memory[1] = 1;
}
void display() {

}
void glutInitRoutines() {
    glutInitWindowSize(64, 32);
    glutCreateWindow("Chip8 V5");
    glutDisplayFunc(display); // die obige Funktion display wird als Bildchirm behandler bekanntgemacht
    //glutSpecialFunc( process_Normal_Keys);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 32.0, 64.0, 0.0);
    //glutIdleFunc( idle);
    glutMainLoop();
    //void glutIdleFunc(void (*func)(void)
}

int main(int argc, char **argv) {
    //screen
    glutInit(&argc, argv);
    glutInitRoutines(); // initialisation for opengGL window
    //screen end
    char rom_name[] = "img Fishie.ch8";

    // #Start Chip8
    C8Klasse c8; // lege interpreter an
    c8.initSpeicher(); // initialisiere den Speicher zu 0
    // #Setup cartridge
    Cartridge testCartridge; // declare a Cartridge ( its the rom with the game data !!
    testCartridge.readInOpcodeFromFileInArray(rom_name); // reads opcode of a data-file (should be in workspace) into an intern array
    testCartridge.printOpcode();
    // # Cartridgecode to Chip8 Memory
    c8.setOpCode(testCartridge);// here the Opcode of the game is passed to the c8 CPU ( Cartridge ->internal memory )!
    c8.printMemory(); // here the c8 internal memory is printed out, should be same form 0x200 to 0xfff with cartridge , since the game has been read in !
    c8.printMemory(0x200); // prints memory by starting at given paramater address !

    cout << "\n please press enter to continue with the program !" << endl;
    cin.get();
    cout << "enter" << endl;
    unsigned short int counter = 0x00; // ein zykluscounter - zählt zeit bis zum nächsten unsigned short interrupt....
    unsigned short int opCode = 0;
    //##########################################################   main loop
    c8.setPC(0x200); // starte mit dem PC auf Adresse 0x200 !
    for (int i = 0; i < testCartridge.getOpcodeLength(); i++) {
        // opCOde is a unsigned short int ( 16 Bit ) the memory is just 8 Bit ! so please make some bit-amipulation: executableOpcode=(opcode1 <<8) | (opcode2)
        opCode = ((unsigned short int) ((c8.getMemAtPC() & (0xff))) << 8);
        c8.incrementPCCounter(1); // increment PC
        opCode = opCode | (((unsigned short int) (c8.getMemAtPC() & (0xff))));
        c8.incrementPCCounter(1); // increment PC -- for the next round
        c8.dissembler(opCode); // so if the opcode variable is fille with 2 Bytes please run the dissembler !
        cout << "\ncurrent pc: 0x" << hex << c8.getPC();
        //      cout << ", the read out OpCode is:0x" << hex << opCode; // show opcode.
        printf(" the read OpCode is: 0x%04x", opCode);
        cin.get();
        // man muss bei den Befehlen unterscheiden:  befehle fangen mit einer fixen Zahl an und haben dann variablen!
        // man muss deswegen zuerst schauen welche zahl am Anfang steht oder , man muss nach einer Zahlenkombinatuon suchen
        //Befehle: http://devernay.free.fr/hacks/chip8/C8TECH10.HTM
        //Hex to ASCII converter : https://www.rapidtables.com/convert/number/hex-to-ascii.html
    }
    return 0;
}
/*
 *
 All instructions are 2 bytes long and are stored most-significant-byte first.
 In memory, the first byte of each instruction should be located at an even addresses.
 3.1 - Standard Chip-8 Instructions
 00E0 - CLS
 00EE - RET
 0nnn - SYS addr
 1nnn - JP addr
 2nnn - CALL addr
 3xkk - SE Vx, byte
 4xkk - SNE Vx, byte
 5xy0 - SE Vx, Vy
 6xkk - LD Vx, byte
 7xkk - ADD Vx, byte
 8xy0 - LD Vx, Vy
 8xy1 - OR Vx, Vy
 8xy2 - AND Vx, Vy
 8xy3 - XOR Vx, Vy
 8xy4 - ADD Vx, Vy
 8xy5 - SUB Vx, Vy
 8xy6 - SHR Vx {, Vy}
 8xy7 - SUBN Vx, Vy
 8xyE - SHL Vx {, Vy}
 9xy0 - SNE Vx, Vy
 Annn - LD I, addr
 Bnnn - JP V0, addr
 Cxkk - RND Vx, byte
 Dxyn - DRW Vx, Vy, nibble
 Ex9E - SKP Vx
 ExA1 - SKNP Vx
 Fx07 - LD Vx, DT
 Fx0A - LD Vx, K
 Fx15 - LD DT, Vx
 Fx18 - LD ST, Vx
 Fx1E - ADD I, Vx
 Fx29 - LD F, Vx
 Fx33 - LD B, Vx
 Fx55 - LD [I], Vx
 Fx65 - LD Vx, [I]
 3.2 - Super Chip-48 Instructions
 00Cn - SCD nibble
 00FB - SCR
 00FC - SCL
 00FD - EXIT
 00FE - LOW
 00FF - HIGH
 Dxy0 - DRW Vx, Vy, 0
 Fx30 - LD HF, Vx
 Fx75 - LD R, Vx
 Fx85 - LD Vx, R
 * */
抢劫

当您调用glutMainLoop()时,您的程序将进入一个看起来像这样的循环:

void glutMainLoop()
{
  while(true)
  {
    MSG msg = getWindowEvent();
    switch(msg)
    {
    case QUIT: exit(0); break; //< NOTE: method never returns!!
    /* snip */
    }
  }
}

这就是调用glutMainLoop()后无法运行任何代码的原因。如果您只想在main的底部一次运行代码(在应用程序启动时),则只需将常规程序功能中的glutMainLoop()移至main()中的最后一个调用即可。如果要更新GL窗口的同时运行该代码,则有两种选择:

  1. 只需在需要时运行std :: cin代码(作为对按键的响应等)。运行该代码时,这将导致OpenGL窗口冻结,这仅仅是因为它是一个单线程应用程序,因此重绘只有在完成后才能进行。
  2. 使用glut keypress / keyrelease回调用输入的文本填充全局std :: string(一次按一次键)。当您检测到回车时,将解析并处理您的操作码,形成全局字符串。不要调用cin并通过OpenGL在屏幕上呈现文本(或者,如果您非常懒惰,请调用glutSetWindowTitle,它避免了查找代码以在屏幕上呈现字体的需求-尽管glut可以帮到您!)
  3. 为基于std :: cin的代码创建第二个线程(如果您确实要这样做?)。然后,您必须处理线程的麻烦,在这种情况下,恕我直言,这可能是过大的了。

就个人而言,我会选择选项2。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何并行运行子程序?

来自分类Dev

如何从命令行运行程序?

来自分类Dev

如何并行运行MSpec测试程序集?

来自分类Dev

如何并行运行MSpec测试程序集?

来自分类Dev

如何并行运行apache

来自分类Dev

如何并行运行DEoptim?

来自分类Dev

如何并行运行剧本

来自分类Dev

并行运行多个应用程序?

来自分类Dev

在Scala中运行的并行程序

来自分类Dev

如何从具有提升权限的命令行运行程序

来自分类Dev

如何并行运行核心 PHP 应用程序和 Codeigniter 应用程序

来自分类Dev

如何并行运行多个Wine实例

来自分类Dev

如何与乘法增量并行运行

来自分类Dev

如何并行运行LINQ'let'语句?

来自分类Dev

如何并行运行Spock测试?

来自分类Dev

如何使该rxjava zip并行运行?

来自分类Dev

如何并行运行Spring Batch作业

来自分类Dev

如何并行运行多个shell脚本?

来自分类Dev

如何使用Julia并行运行方法?

来自分类Dev

如何优化Spark sql以并行运行

来自分类Dev

如何使SBT并行运行测试套件?

来自分类Dev

如何使Selenium与Scrapy并行运行?

来自分类Dev

如何与ThreadPoolExecutor并行运行代码?

来自分类Dev

TeamCity:如何并行运行测试项目

来自分类Dev

如何与Celery并行运行Django方法?

来自分类Dev

如何并行运行多个芹菜任务?

来自分类Dev

如何并行运行不同的方法

来自分类Dev

如何使用TestNG并行运行Selenium?

来自分类Dev

如何检查mapreduce是否并行运行?